DBError

Description

Occurs when a database error occurs in the DataWindow or DataStore.

PowerBuilder event information

Event ID: pbm_dwndberror

Argument

Description

sqldbcode

Long by value. A database-specific error code.

See your DBMS documentation for information on the meaning of the code.

When there is no error code from the DBMS, sqldbcode contains one of these values:

-1 -- Cannot connect to the database because of missing values in the transaction object.

-2 -- Cannot connect to the database.

-3 -- The key specified in an Update or Retrieve no longer matches an existing row. This can happen when another user has changed the row after you retrieved it.

-4 -- Writing a blob to the database failed.

sqlerrtext

String by value. A database-specific error message.

sqlsyntax

String by value. The full text of the SQL statement being sent to the DBMS when the error occurred.

buffer

DWBuffer by value. The buffer containing the row involved in the database activity that caused the error.

For a list of valid values, see DWBuffer.

row

Long by value.

The number of the row involved in the database activity that caused the error (the row being updated, selected, inserted, or deleted).


Return Values

Set the return code to affect the outcome of the event:

0 -- Display the error message and trigger the Transaction object's DBError event if it is defined.

1 -- Do not display the error message, and trigger the Transaction object's DBError event if it is defined.

2 -- Display the error message and ignore the Transaction object's DBError event whether it is defined or not.

3 -- Do not display the error message and ignore the Transaction object's DBError event whether it is defined or not.

For information on setting the return code in a particular environment, see About return values for DataWindow events.

Usage

By default, when the DBError event occurs in a DataWindow control, it displays a system error message. You can display your own message and suppress the system message by specifying a return code of 1 in the DBError event.

Since DataStores are nonvisual, a system message does not display when the DBError event occurs in a DataStore. You must add code to the DBError event to handle the error.

If the row that caused the error is in the Filter buffer, you must unfilter it if you want the user to correct the problem.

Reported row number

The row number stored in row is the number of the row in the buffer, not the number the row had when it was retrieved into the DataWindow object.

Obsolete methods in PowerBuilder

Information formerly provided by the DBErrorCode and DBErrorMessage methods is available in the arguments sqldbcode and sqlerrtext.

Examples

This example illustrates how to display custom error messages for particular database error codes:

CHOOSE CASE sqldbcode
 
      CASE -195 // Required value is NULL.
      MessageBox("Database Problem", &
         "Error inserting row " + string(row) &
         + ". Please specify a value for Employee ID.")
      CASE ...
      // Code to handle other errors
 
END CHOOSE
 
RETURN 1 // Do not display system error message

See also

Error

ItemError

WSError