Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

CommandTimeout does not inherit from Connection timeout


View products that this article applies to.

Symptoms

If a Connection's CommandTimeout property is set to some value and a Command object is associated to that Connection, the Command object does not pickup the Connection's CommandTimeout setting. Instead, the Command object's CommandTimeout is set to its default setting or whatever it was set to prior to being associated with the Connection.

↑ Back to the top


Cause

ActiveX Data Objects (ADO) does not practice inheritance. Due to the stand alone capability of its objects, a Command object can be associated with more than one Connection object. The one exception is the CursorLocation property.

↑ Back to the top


Resolution

Specifically set the Command object's CommandTimeout.

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


More information

Steps to reproduce the behavior

  1. Start a Visual Basic Project.
  2. Set a Project Reference to the Microsoft ActiveX Data Objects Library.
  3. Paste the following code in the Form_Load() event of the default form. You need to modify the connection string so that it references a valid datasouce.
          Dim cnn As New ADODB.Connection
          Dim cnstring As String
          cnstring = "Provider = SQLOLEDB;" & _
                     "DATA SOURCE =<server name>;" & _
                     "USER ID = <user id>;" & _
                     "PASSWORD =<password>;" & _
                     "INITIAL CATALOG = <database>;"
          cnn.CommandTimeout = 0
          cnn.Open cnstring
          Dim cmd As New ADODB.Command
          cmd.ActiveConnection = cnn
          Debug.Print "Timeout on Connection: " & cnn.CommandTimeout
          Debug.Print "Timeout on Command:  " & cmd.CommandTimeout
    					
  4. Run the form. You should see that the timeout for the Connection object is set to zero (0) as expected, while the timeout for the Command object is 30 seconds (which is the default).

↑ Back to the top


Keywords: KB195489, kbprb, kbdatabase

↑ Back to the top

Article Info
Article ID : 195489
Revision : 5
Created on : 7/6/2006
Published on : 7/6/2006
Exists online : False
Views : 418