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.

BUG: Unexpected Cursor Behavior with Set NoCount Statement and SQLOLEDB


View products that this article applies to.

This article was previously published under Q235566

↑ Back to the top


Symptoms

If you try to open a server-side ADO recordset with the "Set NoCount" statement, you would always get ForwardOnly recordset.

This behavior is specific to the OLEDB Provider for SQL Server "SQLOLEDB."

↑ Back to the top


Resolution

Use the OLEDB Provider for ODBC "MSDASQL." -or-

Open the ADO recordset on the Client Side (Static cursor). -or-

Remove the "Set NoCount" statement from your SQL string or stored procedure.

↑ Back to the top


Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


More information

When opening a recordset on the server-side, you would expect the following results:

Collapse this tableExpand this table
Cursor TypeLock TypeExpected Cursor
StaticRead-OnlyStatic
StaticOptimisticDynamic
DynamicAny Lock TypeDynamic


Steps to Reproduce Behavior

  1. Start a new project in Visual Basic. Form1 would be the default form.
  2. Add a Command Button to Form1 (Command1 by default).
  3. Add a reference to "Microsoft ActiveX Data Objects 2.x Library."
  4. Paste the following code into the General Declarations section of Form1. Modify the Connection String to connect to your SQL Server:
    Option Explicit
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim sSQL as String
    
    Private Sub Command1_Click()
    
    Set cn = New ADODB.Connection
    Set rs = New ADODB.Recordset
    
    cn.Open "Provider=SQLOLEDB;User ID=username;Password=password;data source=<Your SQL Server>;Initial Catalog=pubs"
    sSQL = "SET NOCOUNT ON Select * From Authors"
    rs.Open sSQL, cn, adOpenKeyset, adLockOptimistic
    
    If rs.CursorType = adOpenForwardOnly Then
        MsgBox "You have opened a forward-only recordset!"
    End If
    
    rs.Close
    cn.Close
    
    End Sub
    					
  5. Press the F5 key to run the project. You will get the "forward-only recordset" message box.

↑ Back to the top


Keywords: KB235566, kbprovider, kbnofix, kbdatabase, kbbug

↑ Back to the top

Article Info
Article ID : 235566
Revision : 3
Created on : 5/8/2003
Published on : 5/8/2003
Exists online : False
Views : 357