CommandTimeout, ConnectionTimeout, httpRuntime executionTimeout (ASP.NET 2.0)

P

Piotrek

Hi all.

I would like to know what is the difference between these two timeouts:

- CommandTimeout
- ConnectionTimeout


I have following setting in my web.config file:
<httpRuntime executionTimeout="60"/>
Which timeout does it set (command, connection or other)?


Is it possible to globally set CommandTimeout e.g. in web.config?


And last thing: in my app. I get this exception:
System.Web.HttpUnhandledException: Exception of
type 'System.Web.HttpUnhandledException' was thrown. --->
System.Reflection.TargetInvocationException: Exception has been thrown
by the
target of an invocation. ---> System.Data.SqlClient.SqlException:
Timeout
expired. The timeout period elapsed prior to completion of the
operation or
the server is not responding.


What should I do to fix it? I think that I should set CommandTimeout to

some bigger value, but I would like to make it only in one place, not
in every SqlCommand I have.
Is it possible?


Thanks in advance,
Piotrek
 
K

Karl Seguin [MVP]

ConnectionTimeout specifies how long, in seconds, should the code wait
before timing out from trying to OPEN a connection. It relates directly to
the line connection.Oen();

CommandTimeout specified how long, in seconds, should the command wait
before timing out. This relates to calls such as Fill(), ExecuteXXX (Reader,
Scalar, NoQuery) and such. It's relelated to the actual SQL code you are
trying to run (be it inline or an sproc).

the HttpRuntime is how long a request should wait before timing out. This is
much broader than the first two. You can think of it as anything between
your page's init and unload.

CommandTimeout would seem to be your problem. You can't globally set it like
the other two. But you can create a utlity function, so that the code is
centralized.

Karl
 
P

Piotrek

Thanks Karl.

It's a pity that CommandTimeout cannot be globally set. I think I will
create some Session variable and store there value of command timeout
and then assing it to every SqlCommand I have.

One more question: do you know how can I set commandTimeout to fill
method of some TableAdapter, which was created using DataSet Designer?
I am asking, because I cannot find this property.

Best regards,
Piotrek
 
K

Karl Seguin [MVP]

No, I don't off the top of my head.

Also,not sure why you'd store this in the session, why not just do:

internal shared SqlCommand GetSqlCommand()
{
SqlCommand command = new SqlCommand();
command.CommandTimeout =
ConfigurationSettings.ApSettings["commandTimeout"];
return command;
}

or something..

Karl
 
Joined
Apr 15, 2008
Messages
1
Reaction score
0
Do This step at the end of the function

dr.Close(); // Close SqlDataReader
dr.Dispose(); //Dispose SqlDataReader from the from the memory
oConn.cnn.Close(); //Close database Connection
oConn.cnn.Dispose(); // Dispose the database connection from the memory
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top