Thread: How to get the real postgreql error from visual basic

How to get the real postgreql error from visual basic

From
"dfx"
Date:
Dear Sirs,

when I execute a function that returns an error, visual basic shows always
the same error code ( -214767259) but I would like to know the real postgres
code of the error.

The visual basic code that I use is the following:

Dim Cmd As new ADODB.Command
Cmd.CommandText = "delete from <tablename> where id=<some_number>;"
Cmd.ActiveConnection = mvarConnection
Cmd.Execute

Whichever error appens the visual basic Err object returns the same number.


What I have to do?

Any suggestion will be appreciated.

Domenico


R: How to get the real postgreql error from visual basic

From
"Paolo Saudin"
Date:
>>-----Messaggio originale-----
>>Da: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] Per conto di dfx
>>Inviato: domenica 27 luglio 2008 19.37
>>A: pgsql-general@postgresql.org
>>Oggetto: [GENERAL] How to get the real postgreql error from visual basic
>>
>>Dear Sirs,
>>
>>when I execute a function that returns an error, visual basic shows always
>>the same error code ( -214767259) but I would like to know the real
postgres
>>code of the error.
>>
>>The visual basic code that I use is the following:
>>
>>Dim Cmd As new ADODB.Command
>>Cmd.CommandText = "delete from <tablename> where id=<some_number>;"
>>Cmd.ActiveConnection = mvarConnection
>>Cmd.Execute
>>
>>Whichever error appens the visual basic Err object returns the same
number.
>>
>>
>>What I have to do?
>>
>>Any suggestion will be appreciated.
>>
>>Domenico


Hi, I use GetODBCerrors function (which I found somewhere in internet) to
return the errors I get back from PostgreSQL.
Hope  this help

dim m_Dbh As ADODB.Connection
dim m_LastError as String
...
Run query
...
If m_Dbh.Errors.Count > 0 Then  m_LastError = GetODBCerrors


Function GetODBCerrors() As String
    On Error GoTo GetODBCerrors_ErrHandler
    GetODBCerrors = ""
    Dim objError As ADODB.Error
    Dim strError As String
    If m_Dbh.Errors.Count > 0 Then
        For Each objError In m_Dbh.Errors
            strError = strError & "Error #" & objError.Number & " " &
objError.Description & vbCrLf & "NativeError: " _
                    & objError.NativeError & vbCrLf & "SQLState: " &
objError.SQLState & vbCrLf & "Reported by: " & _
                    objError.Source & vbCrLf & "Help file: " &
objError.HelpFile & vbCrLf & "Help Context ID: " & _
                    objError.HelpContext
        Next
        GetODBCerrors = strError
    End If
    Exit Function

GetODBCerrors_ErrHandler:
    GetODBCerrors = Err.Number & " " & Err.Source & " " & Err.Description
End Function


Paolo Saudin