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

From: "Paolo Saudin" <paolo(at)ecometer(dot)it>
To: <dfx(at)dfx(dot)it>, <pgsql-general(at)postgresql(dot)org>
Subject: R: How to get the real postgreql error from visual basic
Date: 2008-07-28 10:44:57
Message-ID: 001b01c8f09e$fac6ca10$f0545e30$@it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>>-----Messaggio originale-----
>>Da: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] Per conto di dfx
>>Inviato: domenica 27 luglio 2008 19.37
>>A: pgsql-general(at)postgresql(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Abhirama Mallela 2008-07-28 11:32:02 Setting up the postgres codebase in Eclipse
Previous Message Craig Ringer 2008-07-28 09:22:33 Re: why my postgresql auto crashed???