I have an old VB6 application that used to be connected to production sybase database. The database was recently migrated to SQL Server 2008 R2 and now I'm the process to update the app to keep it up-and-running. The error I'm getting is "Operation is not allowed when the object is closed".
This is the structure of the code on VB6:
Dim sql as String
Dim connString as String
Dim conn as New ADODB.Connection
connString = "Provider=SQLNCLI10.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=CatalogName;Data Source=Production_Server_Name;"
sql = "EXEC sp_name @param1, @param2, @param3, @param4"
conn.Open connString
Dim Cmd as ADODB.Command
Set Cmd = New ADODB.Command
Set Cmd.ActiveConnection = conn
Cmd.CommandText = sql
Cmd.CommandType = adCmdText
Cmd.CommandTimeOut = 300
Dim rs as ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open sql, conn --> The Code fails on this line !!!
Set rs = Cmd.Execute()
If rs Is Nothing Or IsNull(rs) Then
Set rs = Nothing
bla bla bla
bla bla
End
The stored procedure code is as follows:
CREATE PROCEDURE sp_name
(
@param1 as integer,
@param2 as integer,
@param3 as integer,
@param4 as nvarchar(150)
)
AS
SET NOCOUNT ON
-- All the code goes here
RETURN
Code Structure Notes:
- @param1, @param2 and @param1 are integer defined values. @param4 is comma separated string value
- I already know ADODB objects can be declared and instanciated at the same line.
Validations I already did/Suggestions already tried without success:
- The SP works perfectly when executed from SSMS with a read-only database user.
- The SP DOES use variable tables (@VariableTables) for intermediate processing stuffs.
- The VB6 code WORKS when calling the "sp_who" bult-in SQL Server SP
- The VB6 code WORKS when sql variable contains "SELECT TOP 1 Column FROM DB.dbo.Table"
- The SP FAILS even when using full-qualification for the call (EXEC DB.dbo.sp_name)
- The SP FAILS even when removing the "EXEC" part of the sql variable
Any word to put light on this topic error be really appreciated and the correct answer accepted inmediately.
Thanks in advance