When opening a recordset on the server-side, you would expect the following results:
Collapse this tableExpand this table
Cursor Type | Lock Type | Expected Cursor |
---|
Static | Read-Only | Static |
Static | Optimistic | Dynamic |
Dynamic | Any Lock Type | Dynamic |
Steps to Reproduce Behavior
- Start a new project in Visual Basic. Form1 would be the default form.
- Add a Command Button to Form1 (Command1 by default).
- Add a reference to "Microsoft ActiveX Data Objects 2.x Library."
- 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
- Press the F5 key to run the project. You will get the "forward-only recordset" message box.