Re: ADODB.Recordset: Operation is not allowed when the object is closed
From: Bob Barrows [MVP] (reb01501_at_NOyahoo.SPAMcom)
Date: 11/30/04
- Next message: Richard Mueller [MVP]: "Re: ADODB.Recordset: Operation is not allowed when the object is closed"
- Previous message: Esteban: "Open Files"
- In reply to: William Robertson: "ADODB.Recordset: Operation is not allowed when the object is closed"
- Next in thread: William Robertson: "Re: ADODB.Recordset: Operation is not allowed when the object is closed"
- Reply: William Robertson: "Re: ADODB.Recordset: Operation is not allowed when the object is closed"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 30 Nov 2004 10:08:22 -0500
William Robertson wrote:
> Hi there
>
> I get the above message when trying to write to a SQL 2000 database.
> Can anyone perhpas shed some light on this for me?
>
> In theory I am tryng to create a generic subroutine which I can
> simply pass my INSERT/UPDATE/DELETE statements to, and then have it
> executed. The following subroutine gets called for each server that I
> am running through. The error above is returned on the line
> "objRecordSet2.Close"
>
> My code excerpt is as follows:
> Sub AccessDB()
> ' Set the database connection information
> sServer = "test"
> sLogin = "logon"
> sPwd = "pwd"
>
> ' Create the ADO Connection and Recordset objects.
> Set objConnection2 = CreateObject( "ADODB.Connection" )
> Set objRecordSet2 = CreateObject( "ADODB.Recordset" )
>
> ' Set the connection string, open the connection and execute the
> statement objConnection2.ConnectionString = "PROVIDER=SQLOLEDB" & _
> ";SERVER=" & sServer & _
> ";UID=" & sLogin & _
> ";PWD=" & sPwd & _
> ";DATABASE=ServerSupport"
> WScript.Echo & SQLString
> objConnection2.open
> objRecordSet2.Open SQLString, objConnection2
>
> objRecordSet2.Close
> objConnection2.Close
> End Sub
If your sql string is an insert/update/delete statement, then it will not
return a recordset. DON'T USE A RECORDSET TO EXECUTE A SQL STATEMENT THAT
DOES NOT RETURN RECORDS.
objConnection2.open
objConnection2.Execute SQLString,,129
objConnection2.Close: Set objConnection2 = Nothing
((the 129 tells ADO that you are executing text string containing a sql
statement that does not return records, which prevents ADO from
instantiating a recordset object implicitly. For further explanation, look
up CommandOptionEnum and ExecuteOptionEnum at msdn.microsoft.com/library)
Bob Barrows
-- Microsoft MVP -- ASP/ASP.NET Please reply to the newsgroup. The email account listed in my From header is my spam trap, so I don't check it very often. You will get a quicker response by posting to the newsgroup.
- Next message: Richard Mueller [MVP]: "Re: ADODB.Recordset: Operation is not allowed when the object is closed"
- Previous message: Esteban: "Open Files"
- In reply to: William Robertson: "ADODB.Recordset: Operation is not allowed when the object is closed"
- Next in thread: William Robertson: "Re: ADODB.Recordset: Operation is not allowed when the object is closed"
- Reply: William Robertson: "Re: ADODB.Recordset: Operation is not allowed when the object is closed"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|