Using Server Cursors with ADO

ADO and OLE DB map cursors over the result sets of executed SQL statements. SQLOLEDB implements these operations through the use of server cursors, which are cursors implemented on the server and managed by API cursor functions.

By default, an ADO application does not use Microsoft® SQL Server™ API server cursors with SQLOLEDB. The default cursor used by the ADO application is read-only and forward-only and uses default result set processing.

Cursor Options with SQL Server

Because ADO allows the setting of cursor properties, a number of options exist for using cursors with ADO and SQL Server:

ADO Cursor Settings

An ADO application can control the cursor functionality through the following Recordset properties.

Property Description
CursorType Default: adOpenForwardOnly
Indicates the type of cursor used:
Forward-only/read-only (adOpenForwardOnly)
Static (adOpenStatic)
Keyset (adOpenKeyset)
Dynamic (adOpenDynamic)
CursorLocation Default: adUseServer
Sets or returns the location of the cursor engine. If you set this property to adUseClient, you can only open a static cursor.
LockType Default: adLockReadOnly
Indicates the type of locks placed on records during editing.
CacheSize Default: 1
Controls how many records the provider keeps in its buffer and how many to retrieve at one time into local memory.

Server Cursor Details

To use a server cursor, an application can set these properties to anything other than the default value:

The CursorLocation property should be left at adUseServer, the default setting.

Server cursors are only created for statements that begin with:

Even if an application explicitly requests a server cursor, server cursors are not created for statements such as INSERT.

Server cursors also cannot be used with statements that generate more than one recordset.

This restriction applies to all statements described in Generating Multiple Recordsets. If a server cursor is used with any statement that generates multiple recordsets, an application can get one of the following errors:

This example shows the opening of a dynamic server cursor:

Dim rs As New ADODB.Recordset

. . .

rs.Open "SELECT * FROM titles", , adOpenDynamic, adLockOptimistic

rs.Close

  

See Also
API Server Cursors Default Result Sets
Generating Multiple Recordsets  

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.