1. Hannu Pikkarainen
  2. PowerBuilder
  3. Monday, 9 April 2018 09:20 AM


Where and how can I track DBError of SQLCA transaction object when I'm using Datastore? In Datawindow there is dberror event but how to do it with datastores?

BR, Hannu


Who is viewing this page
Accepted Answer
René Ullrich Accepted Answer Pending Moderation
  1. Monday, 9 April 2018 09:49 AM
  2. PowerBuilder
  3. # Permalink

The is DBError event in datastores. To track this you have to do a little bit more.

1. way: Create an object (n_ds) inherited from datastore. Write code to track errors in that object. e.g.: You may store the error in an instance variable and check this variable after usage.

2. way: You may also use datastores like controls! Insert the datastore user the menu Insert -> Object. Then you can set properties or code events like for datawindows.

... and a code sample for Renè's option #1

Event / Declaration


Code on new n_ds

Instance variables


// Most recent error reported by DBError event

// TIP: Call of_ResetDBError() to clear these data

DWBuffer DBError_Buffer

long     DBError_Row

long     DBError_SQLDBCode

string   DBError_SQLErrText

string   DBError_SQLSyntax

DBError event

// Retain error info in DBError_XXX variables

this.DBError_Buffer = Buffer

this.DBError_Row = Row

this.DBError_SQLDBCode = SQLDBCode

this.DBError_SQLErrText = SQLErrText

this.DBError_SQLSyntax = SQLSyntax

PUBLIC of_ResetDBError

// Clear all DBError_XXX variables

this.DBError_Buffer = Primary!

this.DBError_Row = 0

this.DBError_SQLDBCode = 0

this.DBError_SQLErrText = ""

this.DBError_SQLSyntax = ""

And this shows how you can use such functionality:

Code Example

How to ... Use the new n_ds

// FUNCTION of_Process( )

​// RETURNS  long >= 0: Number of rows processed.

​//                 0: Error.

long ll_retrieveStatus

n_ds lds_data

lds_data = create n_ds

lds_data.DataObject = "d_MyData"


lds_data.of_ResetDBError( )

ll_retrieveStatus = lds_data.Retrieve( ... )

if ll_retrieveStatus 0 then

   // Error occurred during data retrieval

   MessageBox("DB Error During Data Retrieval", &

       "Error Code: " + string(lds_data.DBError_SQLDBCode), &

       "Error Text: " + lds_data.DBError_SQLErrText, &


   return ll_retrieveStatus // Data retrieval failed => ABORT

end if

// Data retrieval succeeded => Process data


NOTE: It is against best practice (though good for demo) to display message boxes in the middle of "non-visual" code.

  1. Michael Kramer
  2. Monday, 9 April 2018 10:58 AM
I would have the DataStore and DataWindow copy the error information to sqlca instead of instance variables. That way you can use your error handling code with DataWindow, DataStore, and inline SQL. I like to record the error info in a database table. I add a function to the Transaction object that records the error in the database and then displays it in a window.

  1. Roland Smith
  2. Monday, 9 April 2018 12:23 PM
I inherited an new object ds_kuormakirja from pfemain.pbl n_ds and used it instead of original datastore type.

ds_kuormakirja kuormakirja

kuormakirja = CREATE ds_kuormakirja

kuormakirja.dataObject = 'dw_kuormakirja'


Now that ds_kuormakirja has already dberror event with all necessary error handling I need. And it can be adjusted for special needs. So simple and I have never thought about it.

Thanks a lot for the help!


  1. Hannu Pikkarainen
  2. Monday, 9 April 2018 12:43 PM
There are no comments made yet.

There are replies in this question but you are not allowed to view the replies from this question.