PRB: "Command Time Out" Property Does Not Work (188858)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 2.0
  • ActiveX Data Objects (ADO) 2.1 SP2
  • ActiveX Data Objects (ADO) 2.5
  • ActiveX Data Objects (ADO) 2.6
  • ActiveX Data Objects (ADO) 2.7

This article was previously published under Q188858

SYMPTOMS

Setting the Recordset's dynamic Command Timeout Property does not time out the query.

RESOLUTION

One workaround for this problem is to switch the cursor from adUseClient to adUseServer.

If adUseClient is necessary, another workaround is to use a Command object as the source of the Recordset and use the Command object's CommandTimeout property, for example:
   'Assuming a connection object has been established
   With oCm

      Set .ActiveConnection = oCn
      .CommandText = "select * from authors"
      .CommandType = adCmdText
      .CommandTimeout = 10

   End With

   With oRs

      .CursorLocation = adUseClient
      .Open oCm

   End With
				

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new Visual Basic project.
  2. On the Project menu, click References, and select Microsoft ActiveX Data Objects 2.x Library.
  3. Add the following code to a Visual Basic form and run the code:
    Note You must change User Id=<username> and Password=<strong password> to the correct values before you run this code. Make sure that User Id has the appropriate permissions to perform this operation on the database.
       Dim oCn As Connection
       Dim oRs As Recordset
       Dim oCm as Command
    
       Set oCn = New Connection
       Set oRs = New Recordset
       Set oCm = New Command
    
       With oCn
          .ConnectionString = "PROVIDER=SQLOLEDB;" & _
                              "DATA SOURCE=<server>;" & _
                              "Initial Catalog=pubs;" & _
                              "User Id=<username>;Password=<strong password>"
          .Open
       End With
    
       'Create a Stored Procedure on SQL Server that causes a delay.
       With oCM
          Set .ActiveConnection = oCn
          .CommandText = "Create Procedure MyWait AS " & _
                          "waitfor delay '00:00:15'"
          .CommandType = adCmdText
          .Execute
       End With
    
       'The Command Time out does not occur.
       With oRs
          Set .ActiveConnection = oCn
          .CursorLocation = adUseClient
          .Properties("Command Time out") = 5
          .Open "MyWait"
       End With

Modification Type:MinorLast Reviewed:3/2/2005
Keywords:kbBug kbDatabase kbpending kbprb KB188858 kbAudDeveloper