Question

I have some ASP (Classic) code that queries a SQL 2005 Express database. I'm currently handling programmatically if this DB goes down by handling the error when someone tries to connect and can't. I capture the error and bypass subsequent db queries to this database using a session variable.

My problem is that this first query takes about 20 seconds before it timeouts.

I'd like to reduce this timeout length but can't find which property either in the code or database is the right one to reduce.

I've tried following in the code;

con.CommandTimeout = 5

con.CONNECTIONTIMEOUT = 5

Any suggestions please?

Thanks,

Andy

Was it helpful?

Solution 2

Ended up using the "Connect Timeout" option within ADODB.Connection string.

e.g.

Set con = Server.CreateObject( "ADODB.Connection" )
con.Open "Provider=SQLOLEDB;Server=databaseserver;User ID=databaseuser;Password=databasepassword;Initial Catalog=databasename;Connect Timeout=5;"

If Err.Number = 0 And con.Errors.Count = 0 Then
    'connected to database successfully
Else
    'did not connect to database successfully within timeout period specified (5 seconds in this example)
End If

OTHER TIPS

First off you should investigate why the DB is going down at all. We manage servers for hundreds of clients and have never run into a problem with the DB going down unless it was scheduled maintenance.

Besides that, you're already onto the right properties.

"Connect Timeout" is set in the connection string and controls how long the client waits to establish a connection to the database. It should be safe to lower this value in most cases--connections should never take long to establish.

"CommandTimeout" is a property on the IDbCommand implementation and controls how long the client waits for a particular query to return. You can lower this value if you know your queries will not take longer than the value you're setting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top