Jump to content

Recommended Posts

Posted

Here 

https://msdn.microsoft.com/en-us/library/windows/desktop/ms675299(v=vs.85).aspx

I read about:

  Quote

Any operation involving ADO objects can generate one or more provider errors. As each error occurs, one or more Error objects can be placed in the Errors collection of the Connection object. When another ADO operation generates an error, the Errors collection is cleared, and the new set of Error objects can be placed in the Errors collection.

As I understand when I use:

#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Error monitoring. This will trap all COM errors while alive.
    ; This particular object is declared as local, meaning after the function returns it will not exist.
    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
    
    ; some ADO STUFF
    ; .....
    ; .....
    ; .....
    ; .....
    ; .....

EndFunc

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 

then I get refrerence to single object not to Collections.

 

 

Question:

How I can get Reference to ErrorCollections ?

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

I think somethink like this:

  Reveal hidden contents

 

 

 

 

So I want to check but actually second question comes to me: How to fires collection of error ?


EDIT:

Finally works:

 

#include <array.au3>
#include "_sql.au3"

Global $oADODB_Connection = ObjCreate("ADODB.Connection")

_Example()
Func _Example()
    ; Error monitoring. This will trap all COM errors while alive.
    ; This particular object is declared as local, meaning after the function returns it will not exist.
    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
    $oADODB_Connection.Open("PROVIDER=SQLNCLI11;SERVER=localhost\SQLExpress;DATABASE=master;uid=sa;pwd=mypass;")
    $oADODB_Connection.BeginTrans
    $oADODB_Connection.Execute('use baza')
    Local $aResult1, $iRows, $iColumns
    _SQL_GetTable2D($oADODB_Connection, 'Select * from table1', $aResult1, $iRows, $iColumns)
    Local $aResult2, $iRows2, $iColumns2
    _SQL_GetTable2D($oADODB_Connection, 'delete from table2', $aResult2, $iRows2, $iColumns2)
    Local $aResult3, $iRows3, $iColumns3
    _SQL_GetTable2D($oADODB_Connection, 'Select * from table3', $aResult3, $iRows3, $iColumns3)
    $oADODB_Connection.CommitTrans
    _ArrayDisplay($aResult1)
    _ArrayDisplay($aResult2)
    _ArrayDisplay($aResult3)


EndFunc   ;==>_Example


; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    Local $err
    Local $iErrorCnt = $oADODB_Connection.errors.Count
    For $iError = 0 to $iErrorCnt
        $err = $oADODB_Connection.errors.Item($iError)
        ConsoleWrite( _
                'ADO Error Collection: ' & $iError & '/' & $iErrorCnt & @CRLF & _
                @ScriptName & " (" & $err.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
                @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($err.number) & @CRLF & _
                @TAB & "err.windescription:" & @TAB & $err.windescription & @CRLF & _
                @TAB & "err.description is: " & @TAB & $err.description & @CRLF & _
                @TAB & "err.source is: " & @TAB & @TAB & $err.source & @CRLF & _
                @TAB & "err.helpfile is: " & @TAB & $err.helpfile & @CRLF & _
                @TAB & "err.helpcontext is: " & @TAB & $err.helpcontext & @CRLF & _
                @TAB & "err.lastdllerror is: " & @TAB & $err.lastdllerror & @CRLF & _
                @TAB & "err.scriptline is: " & @TAB & $err.scriptline & @CRLF & _
                @TAB & "err.retcode is: " & @TAB & "0x" & Hex($err.retcode) & @CRLF & @CRLF)
    Next
EndFunc   ;==>_ErrFunc

 

and to console output:

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "Z:\TOOLs\Macro\FORUM\obj_ErrColl.au3" /UserParams    
+>01:13:43 Starting AutoIt3Wrapper v.15.729.1555.9 SciTE v.3.6.0.0   Keyboard:00000415  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64    Environment(Language:0415)
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\user\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\user\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.0)  from:C:\Program Files (x86)\AutoIt3  input:Z:\TOOLs\Macro\FORUM\obj_ErrColl.au3
+>01:13:44 AU3Check ended.rc:0
>Running:(3.3.14.0):C:\Program Files (x86)\AutoIt3\autoit3.exe "Z:\TOOLs\Macro\FORUM\obj_ErrColl.au3"    
--> Press Ctrl+F11 to Restart or Ctrl+Break -or- F11 to Stop
ADO Error Collection: 0/1
obj_ErrColl.au3 () : ==> COM Error intercepted !
    err.number is:      0x80040E4D
    err.windescription: 
    err.description is:     Login failed for user 'sa'.
    err.source is:      Microsoft SQL Server Native Client 11.0
    err.helpfile is:    
    err.helpcontext is:     0
    err.lastdllerror is:    
    err.scriptline is:  
    err.retcode is:     0x00000000

ADO Error Collection: 1/1
obj_ErrColl.au3 () : ==> COM Error intercepted !
    err.number is:      0x00000000
    err.windescription: 
    err.description is:     
    err.source is:      
    err.helpfile is:    
    err.helpcontext is:     
    err.lastdllerror is:    
    err.scriptline is:  
    err.retcode is:     0x00000000

ADO Error Collection: 0/0
obj_ErrColl.au3 () : ==> COM Error intercepted !
    err.number is:      0x00000000
    err.windescription: 
    err.description is:     
    err.source is:      
    err.helpfile is:    
    err.helpcontext is:     
    err.lastdllerror is:    
    err.scriptline is:  
    err.retcode is:     0x00000000

ADO Error Collection: 0/0
obj_ErrColl.au3 () : ==> COM Error intercepted !
    err.number is:      0x00000000
    err.windescription: 
    err.description is:     
    err.source is:      
    err.helpfile is:    
    err.helpcontext is:     
    err.lastdllerror is:    
    err.scriptline is:  
    err.retcode is:     0x00000000

ADO Error Collection: 0/0
obj_ErrColl.au3 () : ==> COM Error intercepted !
    err.number is:      0x00000000
    err.windescription: 
    err.description is:     
    err.source is:      
    err.helpfile is:    
    err.helpcontext is:     
    err.lastdllerror is:    
    err.scriptline is:  
    err.retcode is:     0x00000000

ADO Error Collection: 0/0
obj_ErrColl.au3 () : ==> COM Error intercepted !
    err.number is:      0x00000000
    err.windescription: 
    err.description is:     
    err.source is:      
    err.helpfile is:    
    err.helpcontext is:     
    err.lastdllerror is:    
    err.scriptline is:  
    err.retcode is:     0x00000000

ADO Error Collection: 0/0
obj_ErrColl.au3 () : ==> COM Error intercepted !
    err.number is:      0x00000000
    err.windescription: 
    err.description is:     
    err.source is:      
    err.helpfile is:    
    err.helpcontext is:     
    err.lastdllerror is:    
    err.scriptline is:  
    err.retcode is:     0x00000000

ADO Error Collection: 0/0
obj_ErrColl.au3 () : ==> COM Error intercepted !
    err.number is:      0x00000000
    err.windescription: 
    err.description is:     
    err.source is:      
    err.helpfile is:    
    err.helpcontext is:     
    err.lastdllerror is:    
    err.scriptline is:  
    err.retcode is:     0x00000000

+>01:13:44 AutoIt3.exe ended.rc:0
+>01:13:44 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 1.095

mLipok

 

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Here is some improvements:

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "Z:\TOOLs\Macro\FORUM\obj_ErrColl.au3" /UserParams    
+>14:29:45 Starting AutoIt3Wrapper v.15.729.1555.6 SciTE v.3.6.0.0   Keyboard:00000415  OS:WIN_81/  CPU:X64 OS:X64    Environment(Language:0415)
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\Michał\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Michał\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.1)  from:C:\Program Files (x86)\AutoIt3  input:Z:\TOOLs\Macro\FORUM\obj_ErrColl.au3
+>14:29:45 AU3Check ended.rc:0
>Running:(3.3.14.1):C:\Program Files (x86)\AutoIt3\autoit3.exe "Z:\TOOLs\Macro\FORUM\obj_ErrColl.au3"    
--> Press Ctrl+F11 to Restart or Ctrl+Break -or- F11 to Stop

! ==> COM Error intercepted ==> ADO Error Collection: .errors.Count = 1   $oErr = .errors.Item(0) 
>   $oErr.description is:       Invalid object name 'table1'.
>   $oErr.number is:        -2147352567   in HEX is  0x80040E37
>      ErrorValueEnum description:  
>   $oErr.source is:        Microsoft SQL Server Native Client 11.0
>   $oErr.SQLState is:      42S02  Description: Base table or view not found
>   $oErr.NativeError is:       208
-   $oError.windescription:     Wystąpił wyjątek.

-   $oError.scriptline is:      21
-   $oError.helpfile is:        
-   $oError.helpcontext is:     0
-   $oError.lastdllerror is:    0
-   $oError.retcode is:         0x80040E37
-   $oError.number is:      0x80020009
! ==> COM End of Error Collections dump.


! ==> COM Error intercepted ==> NOT ADO related Error 
-   $oError.description is:     
-   $oError.number is:      169   in HEX is  0x000000A9
-   $oError.source is:      
-   $oError.windescription:     Variable must be of type 'Object'.
-   $oError.helpfile is:    
-   $oError.helpcontext is:     
-   $oError.lastdllerror is:    0
-   $oError.scriptline is:      23
-   $oError.retcode is:         0x00000000
! ==> COM End of Error dump.

+>14:29:47 AutoIt3.exe ended.rc:0
+>14:29:47 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 2.15

 

EDIT:
oops here you go:  __SQL_ERROR_COLLECTION_TEST.ZIP

Edited by mLipok
fixed problem with attachment

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

I forget to ask.

In the improved version I use such a function:

Func _ErrFunc($oError)
    ; Do anything here.
    Local $iErrorCol_Max = $oADODB_Connection.errors.Count
    If $iErrorCol_Max = 0 Then
        #cs
            ; QUESTION
            ; Why the following VarGetType() return Keyword ?
            Local $oErrorsCollections = $oError.parent
            MsgBox(0, 'VarGetType($oErrorsCollections)', VarGetType($oErrorsCollections))
            Local $vTest = $oErrorsCollections
            MsgBox(0, '$vTest', $vTest)
        #ce
        ConsoleWrite(@CRLF & _
                "! ==> COM Error intercepted ==> NOT ADO related Error " & @CRLF & _
                "-" & @TAB & "$oError.description is: " & @TAB & $oError.description & @CRLF & _
                "-" & @TAB & "$oError.number is: " & @TAB & @TAB & $oError.number & "   in HEX is  0x" & Hex($oError.number) & @CRLF & _
                "-" & @TAB & "$oError.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
                "-" & @TAB & "$oError.windescription:" & @TAB & @TAB & $oError.windescription & @CRLF & _
                "-" & @TAB & "$oError.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
                "-" & @TAB & "$oError.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
                "-" & @TAB & "$oError.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
                "-" & @TAB & "$oError.scriptline is: " & @TAB & @TAB & $oError.scriptline & @CRLF & _
                "-" & @TAB & "$oError.retcode is: " & @TAB & @TAB & "0x" & Hex($oError.retcode) & @CRLF & _
                "! ==> COM End of Error dump." & @CRLF & _
                @CRLF)

    Else
        Local $oErr
        For $iErrorCol_idx = 0 To $iErrorCol_Max - 1
            $oErr = $oADODB_Connection.errors.Item($iErrorCol_idx)
            ConsoleWrite(@CRLF & _
                    "! ==> COM Error intercepted ==> ADO Error Collection: .errors.Count = " & $iErrorCol_Max & "   $oErr = .errors.Item(" & $iErrorCol_idx & ") " & @CRLF & _
                    "-" & @TAB & "$oErr.description is: " & @TAB & @TAB & $oErr.description & @CRLF & _
                    "-" & @TAB & "$oErr.number is: " & @TAB & @TAB & $oError.number & "   in HEX is  0x" & Hex($oErr.number) & @CRLF & _
                    "-" & @TAB & "   ErrorValueEnum description:" & @TAB & _ADO_ERROR_Description("0x" & Hex($oErr.number)) & @CRLF & _
                    "-" & @TAB & "$oErr.source is: " & @TAB & @TAB & $oErr.source & @CRLF & _
                    "-" & @TAB & "$oErr.SQLState is: " & @TAB & @TAB & $oErr.SQLState & '  Description: ' & _SQLState_Description($oErr.SQLState) & @CRLF & _
                    "-" & @TAB & "$oErr.NativeError is: " & @TAB & @TAB & $oErr.NativeError & @CRLF & _
                    "! ==> End of Error Collections dump." & @CRLF & _
                    "! ==> continue with not ADO related Error:" & @CRLF & _
                    "-" & @TAB & "$oError.windescription:" & @TAB & @TAB & $oError.windescription & @CRLF & _
                    "-" & @TAB & "$oError.scriptline is: " & @TAB & @TAB & $oError.scriptline & @CRLF & _
                    "-" & @TAB & "$oError.helpfile is: " & @TAB & @TAB & $oError.helpfile & @CRLF & _
                    "-" & @TAB & "$oError.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
                    "-" & @TAB & "$oError.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
                    "-" & @TAB & "$oError.retcode is: " & @TAB & @TAB & "0x" & Hex($oError.retcode) & @CRLF & _
                    "-" & @TAB & "$oError.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
                    "! ==> COM End of Error dump." & @CRLF & _
                    @CRLF)
        Next
        $oADODB_Connection.errors.clear
    EndIf

EndFunc   ;==>_ErrFunc

I was put there a question:

#cs
    ; QUESTION
    ; Why the following VarGetType() return Keyword ?
    Local $oErrorsCollections = $oError.parent
    MsgBox(0, 'VarGetType($oErrorsCollections)', VarGetType($oErrorsCollections))
    Local $vTest = $oErrorsCollections
    MsgBox(0, '$vTest', $vTest)
#ce

Maybe somebody know the answer ?

 

 

Edited by mLipok
#cs #ce formating in code tag

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 2 weeks later...
Posted

hmm..
Maybe somebody know the answer ?
If so , can you share your knowledge ?

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
  • Recently Browsing   0 members

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