English 中文(简体)
How to reduce timeout period when sql 2005 database unavailable
原标题:

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

最佳回答

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
问题回答

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.





相关问题
SQL Server database is not visible

I have installed ASP.NET application with database on our server. ASP.NET application created database using connection string below. The problem is that I do not see database in SQL Server Management ...

Most efficient way to store number 11.111 in SQL Server

What datatype is the most efficient to store a number such as 11.111. The numbers will have up 2 digits before the point and up to three after. Currently the column is a bigint , I am guessing that ...

表格和数据表

是否需要在提瓜表之后更新表格统计数据,还是自动更新?

Inconsistent Generate Change Script

I add a column of type tinyint and being set to not allow nulls in a table and generate the change scripts. The table has data in it at this time. The script has code that creates a temp table and ...

Performance of Sql subqueriesfunctions

I am currently working on a particularly complex use-case. Simplifying below :) First, a client record has a many-to-one relationship with a collection of services, that is, a single client may have ...

selecting one value out of an xml column

I have a particularly troublesome xml column to query data from. The schema is fixed by the Quebec Ministry of Revenue so "it is what it is" The important part of the query looks like this: with ...

Selecting records during recursive stored procedure

I ve got a content management system that contains a hierarchical structure of categories, with sub-categories subject to different ordering options at each level. Currently, that s retrieved by a (...

热门标签