dbGetError()

Database function that returns the currently waiting error codes and messages.

Synopsis

int dbGetError(dbConnection connection, int &errorCount, int &errorNumber, int &errorNative, string &errorDescription, string &SQLState);

Parameters

Parameter Meaning
connection Connection reference provided by dbOpenConnection()
errorCount Number of queued errors
errorNumber ADO error number
errorNative Error number from the data source (for example, ODBC)
errorDescription Error text
SQLState SQL standard error code

Return Value

The return value is an error code; 0 indicates the operation has been performed successfully.

Errors

An error is returned if an invalid connection reference variable is passed.

Description

If a db method returns an error code (return value <> 0), dbGetError() can be used to obtain exact error details. The errorCount field shows how many error messages are currently waiting. By calling dbGetError() repeatedly, all queued errors can be called up. A full description of the error codes is given in Microsoft's "ADO Programmer's Reference" manual and in the documentation for the data source.

One should note that even when the return value is set after a db...-function call, under certain circumstances the function dbGetError() will not indicate any errors (errorCount = 0). This happens when the error has not been detected by the database but by the ADO interface itself (for example, invalid parameter or the like).

Example

void showError (dbConnection conn)
{
  int errCnt, errNo, errNative;
  string errDescr, errSql;
  int rc;
  errCnt = 1;
  rc = 0;
  while (errCnt > 0 && ! rc)
  {
    rc = dbGetError (conn, errCnt, errNo, errNative, errDescr,
    errSql);
    if (!rc)
    {
      DebugN("Errornumber : ", errNo);
      DebugN("BaseError : ", errNative);
      DebugN("Description : ", errDescr);
      DebugN("SQL-errortext: ", errSql);
    }
    else
    DebugN("dbGetError failed, rc = ", rc2);
    errCnt--;
  }
}

Assignment

ADO and Qt, Database functions

Availability

CTRL