PRB: NextRecordset Fails When Called On a Disconnected Recordset (193352)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 1.5
  • ActiveX Data Objects (ADO) 2.0
  • ActiveX Data Objects (ADO) 2.1 SP2
  • ActiveX Data Objects (ADO) 2.5
  • Microsoft Visual Basic Professional Edition for Windows 5.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0

This article was previously published under Q193352

SYMPTOMS

When trying to retrieve the second recordset in a batch query, one of the following error appears:
The operation requested by the application is not supported by the provider.
-or-
Object or Provider is not capable of performing requested operation.

CAUSE

This problem can be caused by disconnecting the initial recordset prior to calling NextRecordset.

RESOLUTION

Do not disconnect the recordset until you have retrieved all of the recordsets in the batch query.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new Standard .exe project in Visual Basic. Form1 is created by default.
  2. From the Project menu, choose References and then select "Microsoft ActiveX Data Objects 2.0 Library".
  3. Add the following code to your form.

    Note You must change UID <username> and PWD <strong password> to the correct values before you run this code. Make sure that UID has the appropriate permissions to perform this operation on the database.
          Dim cnPubs As ADODB.Connection
          Dim rsBatch As ADODB.Recordset
    
          Private Sub Form_Load()
           Dim strConn As String
           Dim strSQL As String
    
           strConn = "Provider=MSDASQL;Driver={SQL Server};" & _
                     "Server=YourServer;Database=pubs;UID=<user name>;PWD=<strong name>;"
           Set cnPubs = New ADODB.Connection
           cnPubs.CursorLocation = adUseClient
           cnPubs.Open strConn
    
           strSQL = "SELECT * FROM Authors;" & _
                    "SELECT * FROM Employee;" & _
                    "SELECT * FROM Jobs"
           Set rsBatch = New ADODB.Recordset
           rsBatch.Open strSQL, cnPubs, adOpenStatic, _
                        adLockOptimistic, adCmdText
    
           If MsgBox("Disconnect the recordset?", vbYesNo) = vbYes Then
               Set rsBatch.ActiveConnection = Nothing
           End If
    
           Do
               Debug.Print rsBatch(0).Name & " = "  rsBatch(0)
               Set rsBatch = rsBatch.NextRecordset
           Loop Until rsBatch Is Nothing
    
           cnPubs.Close
           Set cnPubs = Nothing
          End Sub
    						
  4. Modify the connection string as appropriate to connect to your SQL Server.
  5. Run the project. When prompted, click Yes to disconnect the recordset. You then receive the error described in the SYMPTOMS section.
  6. Run the project again. When prompted, click No to keep from disconnecting the recordset. You then successfully retrieve the remaining recordsets in the batch query.

(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by David Sceppa, Microsoft Corporation.


Modification Type:MinorLast Reviewed:3/14/2005
Keywords:kbprb KB193352