Bug #28098 ADODB.Recordset.Open "[tablename]", [conn], adOpenKeyset, adLockOptimistic fails
Submitted: 25 Apr 2007 16:29 Modified: 28 Sep 2007 8:32
Reporter: Mark Bewlay
Status: Duplicate
Category:Connector/ODBC Severity:S3 (Non-critical)
Version:3.51.14, 5.0.11 OS:Microsoft Windows (Standard Server 2003 SP 2)
Assigned to: Target Version:

[25 Apr 2007 16:29] Mark Bewlay
Description:
There appears to be an issue been caused when you attempt to open a Recordset object with
a tablename and not an SQL query.  An error is thrown explaining that the SQL in use is
invalid when it attempts to Open the recordset.

In 3.51.12, it is possible to open a recordset like:

set rsRegX = Server.CreateObject("ADODB.Recordset")				
rsRegX.CursorLocation = adUseClient
rsRegX.Open "[tablename]", [conn], adOpenKeyset, adLockOptimistic

However in 3.51.14 this fails, but this works:

set rsRegX = Server.CreateObject("ADODB.Recordset")				
rsRegX.CursorLocation = adUseClient
rsRegX.Open "select * from [tablename]", [conn], adOpenKeyset, adLockOptimistic

How to repeat:
This code is called from within VBScript to either a MySQL4 or MySQL5 database.  Simply
create a table in MySQL and attempt to execute the following code from within a .asp
page.

set rsRegX = Server.CreateObject("ADODB.Recordset")				
rsRegX.CursorLocation = adUseClient
rsRegX.Open "[tablename]", [conn], adOpenKeyset, adLockOptimistic

Suggested fix:
Replace:

rsRegX.Open "[tablename]", [conn], adOpenKeyset, adLockOptimistic

With:

rsRegX.Open "select * from [tablename]", [conn], adOpenKeyset, adLockOptimistic

and the code executes as expected.
[25 Apr 2007 16:30] Mark Bewlay
Please note that this error is appearing when attempting to open a recordset using
VBScript within a .asp page.
[7 May 2007 15:45] Tonci Grgin
Hi Mark and thanks for your report.

Verified as described with test case attached using MySQL 5.0.38BK on WinXP Pro SP2
localhost.

http://msdn2.microsoft.com/en-us/library/ms675544.aspx:
 Source

    Optional. A Variant that evaluates to a valid Command object, an SQL statement, *a
table name*, a stored procedure call, a URL, or the name of a file or Stream object
containing a persistently stored Recordset.
[7 May 2007 15:46] Tonci Grgin
Test case

Attachment: 28098.vbs (application/octet-stream, text), 1.46 KiB.

[7 Sep 2007 11:21] Tonci Grgin
Mark, this is actually a duplicate of Bug#27158. The thing is we do not support
adCmdUnspecified CommandTypeEnum value (-1) which is default... Please try with 2 or 512
like this:
rs.Open "tbl_name",cnxDatabase,adOpenKeyset,adLockOptimistic, 2 ' or 512 works

Lowering the severity as workaround exists.
[7 Sep 2007 11:49] Tonci Grgin
On a second thought there is no way to make this work with CS cursors... Consulting.
[28 Sep 2007 8:32] Tonci Grgin
This is a duplicate of Bug#27158. Please see Kent's explanation there.