English


English


Knowledge base

Impact of ADO cursor types on an ODBC driver in ASP


KB-LJW-DB-101



  




Related articles and resources




ADO / OLE DB / ODBC architecture in Classic ASP

 Click to sort columns
ComponentTypeExamples
1. ASP applicationFunctional logic*.asp files
2. ADOData access APIN/A (standardized library)
3. OLE DBProvider / adapterProvider=MSDASQL;
Provider=Microsoft.ACE.OLEDB.12.0;
Provider=SQLOLEDB;
4. ODBCDriver / driverDriver={MariaDB ODBC 3.2 Driver};
Driver={MySQL ODBC 5.1 Driver};
5. DataFile or Database EngineMariaDB Server 11.4
Microsoft SQL Server
*.mdb file
*.xlsx file


Role of each layer




ADO + OLE DB + ODBC data flow in Classic ASP


Overview



ADO layer



OLE DB layer



ODBC layer




ADO cursor types




Impact of the ADO cursor type






How to take advantage of ADO cursors in ASP?

PHP is not affected by ADO + ODBC


PHP
<?php
$user = 'testUser';
$pass = 'testPassword';
$pdoConn = new PDO('mysql:host=localhost;dbname=TestDB', $user, $pass, [
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);

$sqlStmt = $pdoConn->prepare('SELECT * FROM users WHERE field_1 = :field_1');
$sqlStmt->execute(['field_1' => $_GET['field_1']]);
$result = $sqlStmt->fetch();
?>


PHP
<?php
$conn = new COM("ADODB.Connection");
$conn->Open("Provider=MSOLEDBSQL;Server=localhost;Database=TestDB;Trusted_Connection=Yes;");
?>


ASP.NET is not affected by ADO + ODBC



CursorType for reliable and predictable code



Compatibility of ADO features by Cursor


 Click to sort columns
ADO Method / Property0=Forward-Only (default)3=Static1=Keyset2=Dynamic
MoveNext Yes Yes Yes Yes
MoveFirst No Yes Yes Yes
MoveLast No
(or behavior not guaranteed)
 Yes Yes Yes
MovePrevious No Yes Yes Yes
AbsolutePosition No Yes Yes Yes
PageSize / PageCount / AbsolutePage No Yes Yes Yes
RecordCount Unusable
(returns -1)
 Reliable Reliable Reliable
Bookmark / Supports(adBookmark) No Yes Yes Yes
Sort No
(causes client-side switching)
 Yes
(client-side stable)
 Yes Yes
Filter No
(causes client-side switching)
 Yes Yes Yes
Edit (Update, AddNew, Delete) No
(Read-Only)
 Yes
(but snapshot)
 Yes
(visible rows)
 Yes
(reactive)
See new rows inserted after opening No No No Yes
Concurrent data stabilityVery high (fixed stream)High (snapshot)MediumLow


  • BOF
  • EOF
  • MoveNext
  • Fields
  • Fields.Item
  • Fields.Item("fieldname").Value
  • GetRows
  • GetString
  • State
  • ActiveConnection
  • Source
  • CursorType (retourne 0)
  • CursorLocation
  • LockType
  • CacheSize
  • MarshalOptions



Tips for reliable Classic ASP code with ADO + ODBC


Use CursorType=0 (adOpenForwardOnly) for simple reads of a Recordset


ASP CLASSIC
<%
'Open connection to the database
Set dbConn = Server.CreateObject("ADODB.Connection")
dbConn.Open dbConnString

'Open the Recordset in "Forward-Only" mode via .Open()
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQL, dbConn

''Alternatively: open the Recordset in "Forward-Only" mode via .Execute()
'Set rs = dbConn.Execute(strSQL)
%>


  • BOF
  • EOF
  • MoveNext
  • Fields
  • Fields.Item
  • Fields.Item("fieldname").Value
  • GetRows
  • GetString
  • State
  • ActiveConnection
  • Source
  • CursorType (retourne 0)
  • CursorLocation
  • LockType
  • CacheSize
  • MarshalOptions

ASP CLASSIC
<%
'If the Recordset contains records:
if ((NOT rs.BOF) AND (NOT rs.EOF)) then
   do while NOT rs.EOF
      'Return the value of the "field_1" field
      Response.Write rs("field_1")
      'Proceed to the next record
      rs.MoveNext
   loop
end if
%>




Specify the CursorType before each call to rs.Open

ASP CLASSIC
<%
Set rs = Server.CreateObject("ADODB.Recordset")
'Specify the cursor type
rs.CursorLocation = 3 'adUseClient (Preferably, because server-side cursors depend on the ODBC driver)
rs.CursorType     = 3 'adOpenStatic (or 1 or 2 depending on your needs)
rs.LockType       = 1 'adLockReadOnly (the fastest if no writing required)

'Open the Recordset in a scrollable mode
rs.Open strSQL, dbConn
%>


  • RecordCount
  • MoveFirst
  • MoveLast
  • MovePrevious
  • AbsolutePage
  • PageSize
  • PageCount
  • Sort
  • Filter

ASP CLASSIC
<%
'The recordset was cached in the client-side memory thanks to the rs.CursorType property being different from 0.
'The .Recordcount property is therefore calculable and reflects the actual number of retrieved rows.
if (rs.RecordCount <> 0) then
   'Do something
end if
%>




Specify CursorType=3 (adOpenStatic) for any movement or sorting in a Recordset


  • RecordCount
  • MoveFirst
  • MoveLast
  • MovePrevious
  • AbsolutePage
  • PageSize
  • PageCount
  • Sort
  • Filter





Specify CursorLocation=3 (adUseClient) for any use of rs.Sort and rs.Filter




Managing ADO cursors with the Microsoft SQL Server Driver




Managing ADO cursors with the Microsoft Access Driver




Managing ADO cursors with the MySQL Driver



Default cursor of the MySQL ODBC 3.51 Driver



Default cursor of the MySQL ODBC 5.3 Driver



Use the server-side Forward-Only (streaming) mode (MySQL engine)


Implementation

  • 1048576 (NO_CACHE)
  • 2097152 (FORWARD_CURSOR)



Managing ADO cursors with the MariaDB Driver



Default cursor of the MariaDB ODBC 3.1 Driver



Default cursor of the MariaDB ODBC 3.2 Driver

ODBC-290 = Cursor type now defaults to SQL_CURSOR_FORWARD_ONLY as it is required by specs. 3.1.x series has default cursor type SQL_CURSOR_STATIC.



Use the server-side Forward-Only (streaming) mode (MariaDB engine)


Behavior with MariaDB ODBC 3.1


Behavior with MariaDB ODBC 3.2


Implementation

  • 1048576 (NO_CACHE)
  • 2097152 (FORWARD_CURSOR)
  • FORWARDONLY=1;
  • NO_CACHE=1;





At the service of your ASP Classic





Privacy preferencesYour privacy preferences

NOTE: Your changes will be applied from the next page you will visit/load.

Your privacy is precious: we respect it.

By using this website, you consent that we use technologies such as anonymous statistics and cookies to improve your browsing experience on our site, customise content, and analyse our traffic. This anonymous information may be shared with our trusted social media and analytics partners.

  • We do not collect any nominative data.
  • We do not store any password.
  • We use a high-end secure connection.