Publish date: 2003-03-21

Work with InterBase Exceptions (VB)

Download the example archive
'this sample demonstrates how to use system tables
'for work with Interbase Exceptions
Sub Sample11()

    Dim con As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim cmd As New ADODB.Command

    'open connection to employee.gdb
    Set con = New ADODB.Connection
        con.Open "file name=" & ThisWorkbook.Path & "\employee.ibp"
        con.BeginTrans

        cmd.ActiveConnection = con
        'select exceptions from database
        cmd.CommandText = "select * from rdb$exceptions"
        Set rs = cmd.Execute

        Debug.Print "----------- Begin Exceptions List -------------"
        'print all database exceptions
        Do While Not rs.EOF
           Debug.Print rs.Fields("rdb$exception_name").Value & "='" & _
                       rs.Fields("rdb$message").Value & "'"
           rs.MoveNext
        Loop

        Debug.Print "----------- End Exceptions List -------------"

        'add new exception
        cmd.CommandText = "insert into rdb$exceptions (rdb$exception_name, rdb$message) " & _
                          "values ('IBPROVIDER_EXCEPTION'," & _
                          "'Test new Exception using OLE DB Provider for Interbase')"
        cmd.Execute
        con.CommitTrans
        Debug.Print "New Exception... Add succesful"

        con.BeginTrans
        'update our exception
        cmd.CommandText = "update rdb$exceptions set " & _
                          "rdb$message='Update Exception using OLE DB Provider for Interbase)' " & _
                          "where rdb$exception_name = 'IBPROVIDER_EXCEPTION' "
        cmd.Execute
        con.CommitTrans
        Debug.Print "Exception there Updated"

        con.BeginTrans
        'delete our Exception
        cmd.CommandText = "delete from rdb$exceptions " & _
                          "where rdb$exception_name = 'IBPROVIDER_EXCEPTION' "
        cmd.Execute
        'commit changes
        con.CommitTrans
        Debug.Print "Exception there Deleted"
        'close transaction
        con.Close
        Debug.Print "All Done"
End Sub
Download the example archive