Jump to content

Handling ADO Error


Recommended Posts

In code below, I try to capture an error that cause by .MoveNext

It doesn't work because maybe .MoveNext doesn't generate @error.

$SQLCode = "SELECT blabla;"

$TableContents = _Query ($SQLInstance_Local, $SQLCode)
 
If Not @error Then
    With $TableContents
        While Not .EOF
            ;doing something here
            .MoveNext
            If @error Then
                Msgbox(0,"Error","Server unreachable!")
                Exit
            EndIf
        WEnd
    EndWith
EndIf

How to capture the error WITHOUT using ObjEvent (eg: $objErr = ObjEvent("AutoIt.Error","MyErrFunc")) ?

Edit: the reason I dont want to use $objErr = ObjEvent("AutoIt.Error","MyErrFunc") is because IE.au3 generate a lot of errors

when the error handler is active so the script is pushed to exit.

How to turn off the error handler just for IE.au3?

Edited by michaelslamet
Link to comment
Share on other sites

Which version of AutoIt do you run?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

With AutoIt > 3.3.8.1 the script no longer crashes when a COM error occurres. You simply check @error. So a COM error handler is only needed if you want to retrieve more detailed error information (true for IE UDF and ADO ...).

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

With AutoIt > 3.3.8.1 the script no longer crashes when a COM error occurres. You simply check @error. So a COM error handler is only needed if you want to retrieve more detailed error information (true for IE UDF and ADO ...).

 

I'm not sure if I'm understand you. In this scenario, how to catch the error when --let say-- query all of the records and suddently the server is unreachable?

$SQLCode = "SELECT blabla;"

$TableContents = _Query ($SQLInstance_Local, $SQLCode)
 
If Not @error Then
    With $TableContents
        While Not .EOF
            ;doing something here
            .MoveNext
            If @error Then
                Msgbox(0,"Error","Server unreachable!")
                Exit
            EndIf
        WEnd
    EndWith
EndIf

 

Register an error handler seems doesn't solve it, the error handler doesn't display anything when the connection is broken.

Checking the @error seems not a solution too, because .movenext doesn't return any @error

Link to comment
Share on other sites

How do you now notice that an error occurred? Script crash, error message, @error is set ...?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

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...