Sign in to follow this  
Followers 0
michaelslamet

Handling ADO Error

8 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



Which version of AutoIt do you run?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Which version of AutoIt do you run?

 

Hi Water,

I'm running 3.8.8.1 on WinXP and Win7

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Water,

Thanks for your help :)

The error handler works great, seems just because I place it on the wrong place o:)

Share this post


Link to post
Share on other sites

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0