Search

Thursday, July 21, 2011

CommandTimout Property Problem with Connection Object

The Connection object of the ActiveX Data Objects supports the CommandTimeout property. This property is documented to support a value of 0, which provides for an infinite timeout. This functionality is not available in ActiveX Data Objects 1.0.

The CommandTimeout property functions properly for all values other than 0. If you wish an infinite timeout, you will need to use this parameter in conjunction with the Command object instead. The following example demonstrates how to set the Command object's timeout:

Set MyConn = Server.CreateObject("ADODB.Connection")
MyConn.ConnectionTimeout = 0
MyConn.CommandTimeout = 0
MyConn.Open ConStr, UserId, PassWord
Set cmdTemp = Server.CreateObject("ADODB.Command")
cmdTemp.CommandTimeout = 0

NOTE: The CommandTimeout property on an ADO connection object has no effect on the CommandTimeout property setting of the command object on the same connection. Essentially, the command object's CommandTimeout property does not inherit the value of the connection object's CommandTimeout value.

In order for cmdTemp.CommandTimeout = 0 to work properly, you must use the command object to execute the query.

The following code attempts to set the timeout to 0. When set to this value, the connection object should provide for an indefinite amount of time before timing out. It does not.

Set cn = Server.CreateObject("ADODB.Connection")
cn.CommandTimeout = 0
cn.Open "datasourcename", "userid", "password"
cn.Execute("SQL statement that would cause a timeout")

No comments:

Post a Comment