hi,
I have 480 email in database and want to send email to all of them in one click of button:
I fetch all email like below:
public DataTable GetAllEmail()
{
DataTable dt1 = new DataTable();
using (OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString))
{
con.Open();
OleDbCommand cmd = new OleDbCommand("select * from emailBank where senf=@senf and email <> ''", con);
cmd.Parameters.AddWithValue("@senf", drl_senf.SelectedValue);
cmd.CommandTimeout = 0;
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(dt1);
con.Close();
return dt1;
}
}
but after about 5 minutes I got this error (both in host and locallhost)
The connection has timed out
The server at localhost is taking too long to respond.
I tried
cmd.CommandTimeout = 0;
and
SmtpClient MyMail = new SmtpClient();
MyMail.Timeout = 20000;
but no success
also I tried Connect Timeout=1500 like below <add name="ConStr" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/db1.mdb; Connect Timeout=1500;" providerName="System.Data.OleDb;" /> but it throws this error: An exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll but was not handled in user code
Additional information: Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
and when I change connect Timeout to connection Timeout it throws this error:
An exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll but was not handled in user code
Additional information: Could not find installable ISAM.
using System;
using System.Data;
using System.Data.OleDb;
using Quartz;
using System.Text.RegularExpressions;
/// <summary>
/// Summary description for SendSMS2
/// </summary>
public class SendSMS2 : IJob
{
public void Execute(IJobExecutionContext context)
{
//I called SendMail method for each email in datatable }
public bool SendMail(string pTo, string subject, string body, string atach)
{
}
public DataTable GetAllEmail()
{
}
}
and In global.asax
public static void ConfigureQuartzJobs2()
{
// construct a scheduler factory
ISchedulerFactory schedFact = new StdSchedulerFactory();
// get a scheduler
IScheduler sched = schedFact.GetScheduler();
sched.Start();
IJobDetail job = JobBuilder.Create<SendSMS2>()
.WithIdentity("SendJob")
.Build();
var trigger = TriggerBuilder.Create()
.WithIdentity("SendTrigger")
.WithSimpleSchedule(x => x.WithRepeatCount(0))
//.StartAt(startTime)
.StartNow()
.Build();
sched.ScheduleJob(job, trigger);
}
and I called above method in
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
//ConfigureQuartzJobs();
ConfigureQuartzJobs2();
}
Member
102 Points
247 Posts
The connection has timed out The server at localhost is taking too long to respond.
Jul 15, 2014 03:05 AM|uid571490|LINK
hi,
I have 480 email in database and want to send email to all of them in one click of button:
I fetch all email like below:
and send email to them like below:
but after about 5 minutes I got this error (both in host and locallhost)
The connection has timed out
The server at localhost is taking too long to respond.
I tried
cmd.CommandTimeout = 0;
and
SmtpClient MyMail = new SmtpClient();
MyMail.Timeout = 20000;
but no success
also I tried Connect Timeout=1500 like below
<add name="ConStr" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/db1.mdb; Connect Timeout=1500;" providerName="System.Data.OleDb;" />
but it throws this error:
An exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll but was not handled in user code
Additional information: Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
and when I change connect Timeout to connection Timeout it throws this error:
An exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll but was not handled in user code
Additional information: Could not find installable ISAM.
any Idea? thanks
timeout connection
Contributor
3842 Points
1070 Posts
Re: The connection has timed out The server at localhost is taking too long to respond.
Jul 15, 2014 03:19 AM|cnuonline|LINK
If you are using c# 5 then use Async
timeout connection
Sree..
Member
102 Points
247 Posts
Re: The connection has timed out The server at localhost is taking too long to respond.
Jul 15, 2014 06:55 AM|uid571490|LINK
I have two question
* I fetch emails from database and know the connection is close because
Using {
}
know emails are in datatable and as I know datatable dont need to connection be open,
so why I recive connection timeout error? what's the relation?
* also I think I misunderstand Connection timeout
based on what below link says: The time (in seconds) to wait for a connection to open. The default value is 15 seconds.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectiontimeout%28v=vs.110%29.aspx
connection timeout error take place if the connection doesnt open in 15 seconds am I right?
so why when we fetch this data and show them in gridview, theres not any error?
so is it possible the problem not be related to fetching data from database?
do you mean something like this tutorial?
http://www.aspsnippets.com/Articles/How-to-send-email-Asynchronously-in-ASPNet-using-Background-Thread.aspx
timeout connection
All-Star
25756 Points
7014 Posts
Re: The connection has timed out The server at localhost is taking too long to respond.
Jul 15, 2014 09:05 AM|hans_v|LINK
It's the web server that times out! The process of sending all the emails takes too long, this shouldn't be done in a web page!
timeout connection
Member
102 Points
247 Posts
Re: The connection has timed out The server at localhost is taking too long to respond.
Jul 16, 2014 01:04 AM|uid571490|LINK
thanks hans,
so do you mean I have to do it with a windows Service?
Is there any other choice?
timeout connection
All-Star
25756 Points
7014 Posts
Re: The connection has timed out The server at localhost is taking too long to respond.
Jul 16, 2014 07:47 AM|hans_v|LINK
Yes, I think that would be the best option....
timeout connection
Member
102 Points
247 Posts
Re: The connection has timed out The server at localhost is taking too long to respond.
Jul 17, 2014 03:59 AM|uid571490|LINK
I found another way:
Quartz.net
I test it with about 60 emails, and it worked.
I made a class like this
and In global.asax
and I called above method in
Thanks
resource: http://jalil.faalkhah.com/?m=20131221
only I changed
.WithSimpleSchedule(x => x.WithIntervalInMinutes(1).RepeatForever())
like this:
.WithSimpleSchedule(x => x.WithRepeatCount(0))
becasuse I needed to execute method one times
if anyone see some wrong things in my codes please let me know!
thanks
timeout connection