dcovell Posted August 11, 2006 Share Posted August 11, 2006 Is it possible to perform some type of error handling with SQL? I currently use a function that writes a line to SQL but if the server is down or even worse the server is up but not working correctly, how can I prevent the script from just completely bombing out. I primarily use the SQL for logging and if that fails the rest of the script still needs to run. Here is a sample of the function I am using... Func logtosql($exittext) $DBCon = ObjCreate ("ADODB.Connection") $DBCon.Open ("Provider=SQLOLEDB;Data Source=SERVER;Initial Catalog=DBNAME;User Id=USERNAME;Password=PASSWORD") $DBCon.Execute ("INSERT INTO unlockexitlog (remotemachine,datetimestamp,exittext) Values ('"&$remotePC&"','"&@MON&"/"&@MDAY&"/"&@YEAR&" "&@HOUR&":"&@MIN&":"&@SEC&"','"&$exittext&"')") $DBCon.Close EndFunc Link to comment Share on other sites More sharing options...
bluebearr Posted August 12, 2006 Share Posted August 12, 2006 I'm no expert on this, but in the beta help file it shows how to set up a custom error handler for dealing with COM errors. This might help you trap various errors and branch appropriately. Do a search for "COM Error Handling" BlueBearrOddly enough, this is what I do for fun. Link to comment Share on other sites More sharing options...
dcovell Posted August 14, 2006 Author Share Posted August 14, 2006 Thank you, I found what you are talking about and plan to look though the examples and see what I can come up with. $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler ; Performing a deliberate failure here (object does not exist) $oIE = ObjCreate("InternetExplorer.Application") $oIE.visible = 1 $oIE.bogus if @error then Msgbox(0,"","the previous line got an error.") Exit ; This is my custom error handler Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _ "Number is: " & $HexNumber & @CRLF & _ "Windescription is: " & $oMyError.windescription ) SetError(1) ; something to check for when this function returns Endfunc Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now