Jump to content

Getting an error with no issues...


Jewtus
 Share

Recommended Posts

I have been trying to figure out what is causing this error:

 

 
err.number is: 80020009
err.lastdllerror is: 0
err.scriptline is: 266
err.source is: ADODB.Recordset
err.helpfile is: C:WindowsHELPADO270.CHM
err.helpcontext is: 1240653_______------- Error -------_______
err.description is: Operation is not allowed when the object is closed.
err.windescription: Exception occurred.

 

 

 

This error is generated on the following lines:

$sqlRs = ObjCreate("ADODB.Recordset")
$sqlRs.open ($InsertQuery, $sqlCon)
ConsoleWrite($InsertQuery&@CRLF)
$sqlRs.close

The line that generates the error is the open line. I put console write in so I could execute the query manually and see if I get an error, but I don't, and the record also appears to have inserted without any issues so I'm not sure what exactly this error is all about.

Edited by Jewtus
Link to comment
Share on other sites

 

You've left out a few details such as the declaration and opening of the sql connection and the sql statement that you are trying to execute. You may want to try this instead of using an ADO recordset:

$sqlCon.Execute($InsertQuery)

The declaration was left out because it was a connection string to a private DB, but here is an obfuscated version of it:

$sqlCon = ObjCreate("ADODB.Connection")
$sqlCon.Open ('Provider=SQLOLEDB.1;Password={PASSWORD};Persist Security Info=True;User ID={USERNAME};Initial Catalog={CATALOG};Data Source={HOSTNAME};')
If @error Then
    MsgBox(0, "ERROR", "Failed to connect to the database")
    Exit
EndIf

The insert statement is pretty basic...

 

Insert into {Table} Values ('value 1', 'value 2','value 3')

 

 I did try to replace the $sqlCon.Open with $sqlCon.Execute but I get the error  "Unknown Name"

 

Well the standard thing to do is add error checking to your code which will help you debug the problem.

Not sure I understand... I do have an error check in that is kicking up the error that I put in the OP. The error states:

Operation is not allowed when the object is closed.

This indicates I have something wrong with the syntax in my statement, but the commands ARE executing. I have the following to capture errors:

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

Func MyErrFunc()
  $HexNumber=hex($oMyError.number,8)
  MsgBox(0,"","_______------- Error -------_______"       & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )
  SetError(0)  ; to check for after this function returns
Endfunc

The only reason I care about figuring out this issue (because the sql statements seem to transact without any issues) is because for deployment purposes I change the error handler to a logger:

Func MyErrFunc()
  $HexNumber=hex($oMyError.number,8)
  FileWrite($logFile,"_______------- Error -------_______"       & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )
  SetError(0)  ; to check for after this function returns
Endfunc

And when I run my script, there are several hundred inserts, which makes the log file extremely long for each execution.

Link to comment
Share on other sites

UPDATE:

I commented out the $sqlRs.close from my OP and it doesn't kick up errors and it appears to transact without issues.

Why would Inserts not require a connection to be closed but selects in combination with .getrows do need to close the connection or (when running a loop) it wont reset the dataset?

Edited by Jewtus
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...