SQL timeout error

  • Thread starter Thread starter Martin Eyles
  • Start date Start date
M

Martin Eyles

I am trying to perform a very long query on an MSSQL database, using
ASP.NET, and making the code behind in VB.NET. I have been receiving timeout
error, so I thought I would add Connect Timeout to my connection string.
However this appears to have no effect. The connection string is set up as
follows

Dim conn As New SqlClient.SqlConnection("Data Source=serverName; User
ID=userName; Password=password; Connect Timeout=9999")

Any ideas why this isn't changing the timeout?

Thanks,
Martin
 
What you are setting is the connection timeout. That means how long the
connection waits while trying to connect to the database server before
giving up.

This is in no way related to the timeout when executing commands. Not sure
why you thought it would be.

Follow Gary's advice for setting the CommandTimeout to control the timeout
while executing commands.
 
Yes,

You getting the settings wrong.

Connect Timeout is the amount of time to ~find the server.

Command Timeout is the amount of time.. for instance, a proc runs before
timing out.

You need Command Timeout.
 
I'm having the same problem, but in my case, I'm using the default Database
adapter, not the Object adapter (middle tier). Hence, I don't see a way to
get a hold of the CommandTimeout property since I'm not the one that is
creating the SqlCommand object.

Am I stuck or is there another way? I'm not inclined to change my code to
use Object adapter at this point.

Thanks,
Jef
 
Never mind. I found the solution in aspnet section. If anyone is interested,
the answer comes from Walter Wang:

You can set the select command's timeout value in SqlDataSource's Selecting
event:

protected void SqlDataSource1_Selecting(object sender,
SqlDataSourceSelectingEventArgs e)
{
e.Command.CommandTimeout = 30;
}
 
Back
Top