How to differentiate error using adodb.recordset in vba

Hi experts,
How can I  differentiate oracle error between connection error and other errers in vba.
I tried the code bellow. But not only when internet cable is disconnected but also when sql syntax error happened , the code show ORACLE CONNECTING ERROR.

Public Function TEST() As Boolean
    Dim strSql As String
    Dim oraDS As OraDynaset
    On Error GoTo ERR
    strSql = ""
    strSql = " select COLUMN from TALE "
    Set OraRec = New ADODB.Recordset
    OraRec.Open strSql, OraCon, adOpenKeyset, adLockReadOnly
       
    Exit Function

ERR:
    If OraCon.State <> adStateOpen Then
        MsgBox "ORACLE CONNECTING ERROR"
    Else
        MsgBox "ORACLE SQL SYNTAX ERROR"
    End If
End Function
Sat NunaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
you got to refer to Err.Description in particular to get the exact error.

But not only when internet cable is disconnected but also when sql syntax error happened , the code show ORACLE CONNECTING ERROR.
can you put a break point in your codes and see what's the State of connection when sql syntax error was happened?

or you can try refer to adStateClosed state instead?

If OraCon.State <> adStateClosed Then
        MsgBox "ORACLE CONNECTING ERROR"
    Else
        MsgBox "ORACLE SQL SYNTAX ERROR"
    End If

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sat NunaAuthor Commented:
Than you letting me know using Err.Description. Err.Description was ORA-03113 when internet cable is disconnected.
So I tried to modify my code bellow, And It worked.
Thanks.

If Mid(ERR.Description, 5, 5) = "03113" Then
        MsgBox "ORACLE CONNECTING ERROR"
Else
        MsgBox "ORACLE SQL SYNTAX ERROR"
End If

If there is something wrong with this code , please let me know.
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
coool, and you can refer to Err.Number when necessary, see if you get 03113 or similar value there?
0
Sat NunaAuthor Commented:
I like to use ERR.Description.
Thank you very much.
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
just a note for correction.

I think I got my comment wrong for adStateClosed condition:

>>If OraCon.State <> adStateClosed Then
 >>MsgBox "ORACLE CONNECTING ERROR"
>>Else
>>MsgBox "ORACLE SQL SYNTAX ERROR"
>>End If

it should be as:

If OraCon.State = adStateClosed Then
MsgBox "ORACLE CONNECTING ERROR"
Else
 MsgBox "ORACLE SQL SYNTAX ERROR"
End If
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.