travish1 0 Posted April 17, 2013 Alright, I'm bashing my head in on this one. Can anyone give me a hint as to why @error isn't catching when an invalid server is provided? Instead, the script quits and provides this error: C:\Scripts\EEG Data Migration.au3 (284) : ==> The requested action with this object has failed.: $sqlCon.Open($sqlConStr) $sqlCon.Open($sqlConStr)^ ERROR $sqlConStr = "DRIVER={SQL Server};SERVER=" & $strDbServer & ";DATABASE=MainExamDataDB;uid=TP;pwd=;" $sqlCon = ObjCreate("ADODB.Connection") $sqlCon.Open($sqlConStr) If @error Then $dbConnectError = MsgBox(48, "Error", "Failed to connect to the database, please verify the server.") $sqlCon.Close WinActivate("EEG Data Migration Parameters") ControlFocus("EEG Data Migration Parameters", "", 5) Else queryStudiesToTransfer() EndIf Any help would be greatly appreciated! Share this post Link to post Share on other sites
kylomas 415 Posted April 17, 2013 travish1, You can use an error handler to process this kind of error...do a search on it. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Share this post Link to post Share on other sites
travish1 0 Posted April 18, 2013 Thanks for the tip, kylomas. I had attempted the error handler. This worked well except that it would still throw an EOF error even when the DB connection was successful. The error is listed below. $oErrorHandler = ObjEvent("AutoIt.Error", "objError") err.number is: -2147352567 err.windescription: err.description is: Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record. err.source is: ADODB.Recordset My guess is that I'm getting this error because I haven't run a query; however, I'm hoping to have this as a separate function for establishing the database connection. ;Function to connect to database Func dbConnect() $sqlConStr = "DRIVER={SQL Server};SERVER=" & $strDbServer & ";DATABASE=MainExamDataDB;uid=TP;pwd=;" $sqlCon = ObjCreate("ADODB.Connection") $oErrorHandler = ObjEvent("AutoIt.Error", "objError") $sqlCon.Open($sqlConStr) If @error Then $dbConnectError = MsgBox(48, "Error", "Failed to connect to the database, please verify the server.") $sqlCon.Close WinActivate("EEG Data Migration Parameters") ControlFocus("EEG Data Migration Parameters", "", 5) Else queryStudiesToTransfer() EndIf EndFunc Func objError($oError) ConsoleWrite("err.number is: " & @TAB & $oError.number & @CRLF & _ "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ "err.description is: " & @TAB & $oError.description & @CRLF & _ "err.source is: " & @TAB & $oError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ "err.retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF) $dbConnectError = MsgBox(48, "Error", "Failed to connect to the database, please verify the server." & @CRLF & @CRLF & "Error: " & $oError.number & @CRLF & "Description: " & $oError.description) $sqlCon.Close WinActivate("EEG Data Migration Parameters") ControlFocus("EEG Data Migration Parameters", "", 5) EndFunc Share this post Link to post Share on other sites
kylomas 415 Posted April 18, 2013 travish1, What are you doing in queryStudiesToTransfer()? You should be able to establish the connection anywhere, as long as the entire script has visibility to whatever variables are being used. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Share this post Link to post Share on other sites
water 2,359 Posted April 18, 2013 A few tips:Put the ObjEvent statement to grab COM errors at the top of your script to make sure you grab all errorsMove those WinActivate("EEG Data Migration Parameters"), queryStudiesToTransfer etc. statemtents out of function DBConnect. Like the name says the function should only connect to the DBNo $sqlCon.Close is needed if $sqlCon.Open was not successfull My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites