abiteric Posted September 14, 2010 Posted September 14, 2010 $conn = ObjCreate("ADODB.Connection") $rs = ObjCreate("ADODB.Recordset") Func _openDb() $conn.close ;~ never open, so Error if @error then return -1 EndFunc _openDb()console debug : The requested action with this object has failed.:$conn.close$conn.close^ ERRORHow do i detect any error on $conn ? My website about Y-mate 網拍輔助程式 : http://www.L2play.comMy Blog ( Tranditional Chinese ) 開發小組的部落格 : http://tw.myblog.yahoo.com/play19990909
water Posted September 14, 2010 Posted September 14, 2010 (edited) You need a COM error handler. I use the following in my AD.UDF. Modify it to your needs. expandcollapse popup$oAD_MyError = ObjEvent("AutoIt.Error", "_AD_ErrorHandler") ; at the top of your script Func _AD_ErrorHandler() Local $bAD_HexNumber = Hex($oAD_MyError.number, 8) Local $sAD_Error = "COM Error Encountered in " & @ScriptName & @CRLF & _ "Scriptline = " & $oAD_MyError.scriptline & @CRLF & _ "NumberHex = " & $bAD_HexNumber & @CRLF & _ "Number = " & $oAD_MyError.number & @CRLF & _ "WinDescription = " & StringStripWS($oAD_MyError.WinDescription, 2) & @CRLF & _ "Description = " & StringStripWS($oAD_MyError.description, 2) & @CRLF & _ "Source = " & $oAD_MyError.Source & @CRLF & _ "HelpFile = " & $oAD_MyError.HelpFile & @CRLF & _ "HelpContext = " & $oAD_MyError.HelpContext & @CRLF & _ "LastDllError = " & $oAD_MyError.LastDllError If $iAD_Debug > 0 Then If $iAD_Debug = 1 Then ConsoleWrite($sAD_Error & @CRLF & "========================================================" & @CRLF) If $iAD_Debug = 2 Then MsgBox(64, "Active Directory Functions - Debug Info", $sAD_Error) If $iAD_Debug = 3 Then FileWrite("AD_Debug.txt", @YEAR & "." & @MON & "." & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " " & @CRLF & _ "-------------------" & @CRLF & $sAD_Error & @CRLF & "========================================================" & @CRLF) EndIf $iAD_COMErrorDec = $oAD_MyError.number Switch $bAD_HexNumber ; 8007054B: ERROR_NO_SUCH_DOMAIN - The specified domain either does not exist or could not be contacted Case "8007054B" $iAD_COMError = 2 ; 80020009: DISP_E_EXCEPTION - Unanticipated error occurred ; 80072030: LDAP_NO_SUCH_OBJECT - Object does not exist Case "80020009", "80072030" $iAD_COMError = 3 ; 8007203A: LDAP_SERVER_DOWN - The server is not operational. Can be caused by hitting a domain controller too hard Case "8007203A" $iAD_COMError = 4 ; 80005000: E_ADS_BAD_PATHNAME - An invalid ADSI path name was passed Case "80005000" $iAD_COMError = 5 ; 800706BA: RPC_S_SERVICE_UNAVAILABLE - The RPC-Server is not available Case "800706BA" $iAD_COMError = 6 Case Else MsgBox(262144, "Active Directory Functions", $sAD_Error) $iAD_COMError = 1 EndSwitch EndFunc ;==>_AD_ErrorHandler Edited September 14, 2010 by water My UDFs and Tutorials: Reveal hidden contents UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
abiteric Posted September 15, 2010 Author Posted September 15, 2010 Thanks! My website about Y-mate 網拍輔助程式 : http://www.L2play.comMy Blog ( Tranditional Chinese ) 開發小組的部落格 : http://tw.myblog.yahoo.com/play19990909
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