dotConnect for DB2 Documentation
Devart.Data.DB2 Namespace / DB2Exception Class
Members Example

In This Topic
    DB2Exception Class
    In This Topic
    The exception that is generated when DB2 server returns an error.
    Syntax
    Remarks
    This class is created whenever dotConnect for DB2 encounters an error generated by the server, or when the DB2Connection has been closed before attempting to execute an operation on the server.
    Example
    The following example generates DB2Exception, containing DB2ErrorCollection, due to inserting NULL values to NOT NULL columns. Then the example outputs DB2Error messages to console.
    DB2Connection connection = new DB2Connection("User ID=db2admin;Password=db2admin;Server=db2;Database=SAMPLE");
    connection.Open();
    try {
    DB2Loader loader = new DB2Loader("DEPT", connection);
        loader.Open();
        loader.NextRow();
        loader["DEPTNO"] = 111;
        loader["DNAME"] = DBNull.Value; // database field cannot contain NULL values
        loader["LOC"] = "NEW YORK";
        loader.NextRow();
        loader["DEPTNO"] = 1;
        loader["DNAME"] = DBNull.Value; // database field cannot contain NULL values
        loader["LOC"] = "CHICAGO";
        loader.NextRow();
        loader["DEPTNO"] = 2;
        loader["DNAME"] = DBNull.Value; // database field cannot contain NULL values
        loader["LOC"] = "DALLAS";
        loader.Close();
    }
    catch (DB2Exception ex) {
        foreach (DB2Error error in ex.Errors) {
            Console.WriteLine("Message: " + error.Message + Environment.NewLine +
            "Native: " + error.NativeError.ToString() + Environment.NewLine +
            "Source: " + error.Source);
        }
    }
    Dim connection As New DB2Connection("User ID=db2admin;Password=db2admin;Server=db2;Database=SAMPLE")
    connection.Open()
    Try
    Dim loader As New DB2Loader("DEPT", connection)
            loader.Open()
            loader.NextRow()
            loader("DEPTNO") = 111
            loader("DNAME") = DBNull.Value
            ' database field cannot contain NULL values
            loader("LOC") = "NEW YORK"
            loader.NextRow()
            loader("DEPTNO") = 1
            loader("DNAME") = DBNull.Value
            ' database field cannot contain NULL values
            loader("LOC") = "CHICAGO"
            loader.NextRow()
            loader("DEPTNO") = 2
            loader("DNAME") = DBNull.Value
            ' database field cannot contain NULL values
            loader("LOC") = "DALLAS"
            loader.Close()
    Catch ex As DB2Exception
            For Each [error] As DB2Error In ex.Errors
                    Console.WriteLine((("Message: " + [error].Message _
                + Environment.NewLine & "Native: " & [error].NativeError.ToString()) _
                + Environment.NewLine & "Source: ") + [error].Source)
            Next
    End Try
    Inheritance Hierarchy

    System.Object
       System.Exception
          System.SystemException
             System.Runtime.InteropServices.ExternalException
                System.Data.Common.DbException
                   Devart.Data.DB2.DB2Exception

    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also