C Examples: DbiGetErrorString

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

C Examples: DbiGetErrorString

Return to chapter overview

Check the BDE error stack for error information:

This example uses the following input:
         fError(DbiSaveChanges(hCur));

DBIResult fError(DBIResult ErrorValue)

{

  char        dbi_status[DBIMAXMSGLEN * 5] = {'\0'}; // Error String

  DBIMSG      dbi_string = {'\0'};

  DBIErrInfo  ErrInfo;    // Contains information about the error

 

  if (ErrorValue != DBIERR_NONE)

  {

     // Note - make certain to call DbiGetErrorInfo() right after

     // the error because it will give information about only the

     // most recent error.

     DbiGetErrorInfo(TRUE, &ErrInfo);

 

     if (ErrInfo.iError == ErrorValue)

     {

        strcpy(dbi_status, ErrInfo.szErrCode);

 

        // Need to check how much information was provided -

        //   different errors return different amounts of information.

        if (strcmp(ErrInfo.szContext1, ""))

           wsprintf(dbi_status, "%s\r\n    %s", dbi_status, ErrInfo.szContext1);

        if (strcmp(ErrInfo.szContext2, ""))

           wsprintf(dbi_status, "%s\r\n    %s", dbi_status, ErrInfo.szContext2);

        if (strcmp(ErrInfo.szContext3, ""))

           wsprintf(dbi_status, "%s\r\n    %s", dbi_status, ErrInfo.szContext3);

        if (strcmp(ErrInfo.szContext4, ""))

           wsprintf(dbi_status, "%s\r\n    %s", dbi_status, ErrInfo.szContext4);

     }

     else

     {

        DbiGetErrorString(ErrorValue, dbi_string);

        strcpy(dbi_status, dbi_string);

     }

     // Display error in snipit and in a MessageBox

     MessageBox(NULL, dbi_status, "BDE Error - Example Only", MB_ICONEXCLAMATION);

  }

  return ErrorValue;

}