
Problem ( Bug ?? ) with ADODB ( 2.1, 2.5, 2.6 SP1 )
HI
A problem with ADODB Recordset ( 2.1, 2.5, 2.6 SP1) ?
If we have a Stored Procedure on SQL Server 2000
which has both an ( Update or Insert or Delete )
and a Select which returns a Result Set then the
ADODB Recordset does not return the Result Set of
the Select in the Stored Procedure.
When such a Stored Procedure is called using ADODB
with the SQLOLEDB provider for SQL Server 2000,
the ADODB Recordset gives an error when an attempt
is made the access the Recordset.
The following setup simulates this problem with the
ADODB Recordset
1. A table "tblADODBTest" with two columns "Col1" "Col2"
TSQL for creating the table:
create table tblADODBTest
( Col1 varchar(10), Col2 varchar(10) )
go
2. A Stored Proc with an Insert and a Select.
TSQL for creating the a :
create proc pr_ADODBTest as
begin
insert into tblADODBTest
values ( 'Val1', 'Val2' )
select * from tblADODBTest
end
go
3. VB code that call the Stored Procedure "pr_ADODBTest"
using ADODB and SQLOLEDB provider for SQL Server 2000.
Sub ADODBTest()
Dim oRs As ADODB.Recordset
Dim oCmd As ADODB.Command
Dim oConn As ADODB.Connection
Dim sConnection As String
Dim sProcName As String
sConnection = "Provider=SQLOLEDB;Data Source=SomeDBServer;Initial
Catalog=SomeDB;User Id=sa;Password=SomePassword;"
sProcName = "pr_ADODBTest"
Set oConn = New ADODB.Connection
With oConn
.CursorLocation = adUseClient
.ConnectionTimeout = 15
.IsolationLevel = adXactReadUncommitted
.Open sConnection
End With
Set oCmd = New ADODB.Command
With oCmd
Set .ActiveConnection = oConn
.CommandTimeout = 30
.CommandType = adCmdStoredProc
.CommandText = sProcName
End With
Set oRs = oCmd.Execute()
' The state is closed ??!!
Debug.Print oRs.State
' This is where we get an error since the
' Recordset is closed. ( The Recordset never opened ?? )
oRs.ActiveConnection = Nothing
' The execution never reaches this point
Dim vResultSet As Variant
If Not oRs.EOF Then
avarResultSet = oRs.GetRows()
End If
End Sub
The above VB Code works fine when the Insert statement is removed
from the Stored Procedure "pr_ADODBTest"
Is this a bug ? Is there any solution or work around to
this problem ?
Thanks and Regards
Rahul