Help and Support

PRB: CursorType Returns adOpenStatic When You Request adOpenDynamic from a Server-Side Recordset

Article ID:306385
Last Review:June 30, 2004
Revision:3.0
This article was previously published under Q306385
On This Page

SYMPTOMS

When you use a Microsoft SQL Server stored procedure to request a dynamic recordset with the CursorLocation property set to adUseServer, the recordset is returned with a CursorType of adOpenStatic instead of adOpenDynamic.

This problem only occurs if there are user-defined variables in the stored procedure or SQL commands such as SET NOCOUNT ON.

Back to the top

STATUS

Microsoft is currently reviewing this issue and updates will be added to this article as they become available.

Back to the top

MORE INFORMATION

Steps to Reproduce Behavior

1.Create a Data Source Name (DSN) named SQLPUBS that points to the SQL Server Pubs database.
2.In the SQL Server Enterprise Manager, modify the ByRoyalty stored procedure. Add SET NOCOUNT ON immediately following the AS portion of the stored procedure, and save the changes.
3.Create a new Visual Basic Standard EXE project.
4.From the Project menu, click References, and then select the Microsoft Data Access Objects 2.x Library check box.
5.Paste the following code in the form load event:
Dim rs As ADODB.Recordset
    Dim comm As ADODB.Command
    Dim oCon As New ADODB.Connection
    Dim prm As ADODB.Parameter
    Dim StrOut As String
        
    StrOut = ""
    oCon.Open "DSN=SQLPUBS;uid=XXX;password=YYY;"
    Set comm = New ADODB.Command
    Set comm.ActiveConnection = oCon
    comm.CommandText = "byroyalty"
    Set prm = comm.CreateParameter("@percentage", adInteger, adParamInput, , 25)
    comm.Parameters.Append prm
    Set rs = New ADODB.Recordset
    
    'rs.CursorLocation = adUseClient
    rs.CursorLocation = adUseServer
    
    rs.Open comm, , adOpenDynamic, adLockBatchOptimistic
   
    StrOut = "rs.CursorType = " & rs.CursorType
    Select Case rs.CursorType
        Case 0
            Debug.Print StrOut & " - adOpenForwardOnly"
        Case 1
            Debug.Print StrOut & " - adOpenKeySet"
        Case 2
            Debug.Print StrOut & " - adOpenDynamic"
        Case 3
            Debug.Print StrOut & " - adOpenStatic"
    End Select
					
6.Modify the following string to reflect your SQL Server UserID and password:
oCon.Open "DSN=SQLPUBS;uid=XXX;password=YYY;"
					
7.Save and run the project. Notice that the following output appears in the local window:
rs.CursorType = 3 - adOpenStatic
							
instead of:
rs.CursorType = 2 - adOpenDynamic
						

Back to the top

REFERENCES

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:
123008 (http://support.microsoft.com/kb/123008/EN-US/) HOWTO: Set Up ODBC Data Sources When Distributing Apps
171146 (http://support.microsoft.com/kb/171146/EN-US/) HOWTO: Create and Remove a DSN in Visual Basic
306388 (http://support.microsoft.com/kb/306388/EN-US/) PRB: CursorType Returns adOpenStatic from Server-Side Recordset and Behaves Like a Forward-Only Recordset

Back to the top


APPLIES TO
Microsoft ActiveX Data Objects 2.5
Microsoft ActiveX Data Objects 2.6
Microsoft ActiveX Data Objects 2.7
Microsoft SQL Server 7.0 Standard Edition
Microsoft SQL Server 7.0 Service Pack 1
Microsoft SQL Server 7.0 Service Pack 2
Microsoft SQL Server 7.0 Service Pack 3
Microsoft ODBC Driver for Microsoft SQL Server 3.7
Microsoft SQL Server 2000 Service Pack 3a
Microsoft SQL Server 2000 Service Pack 1
Microsoft Visual Basic 6.0 Enterprise Edition
Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 3
Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 4
Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 5

Back to the top

Keywords: 
kbprb kbpending KB306385

Back to the top

Article Translations

 

Other Support Options

  • Contact Microsoft
    Phone Numbers, Support Options and Pricing, Online Help, and more.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.