Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

how to get db error message when activing table?

nora_ttnora_tt Posts: 10Member
my database is mysql,after closing impropertyly table,i again open a message writing
"project xxx.exe raised exception class EDatabaseError with message'
got error 127 from table handle'

my intention is when activing table,how can i get it ?


  • injektiloinjektilo Posts: 113Member
    Information that describes the conditions of a database engine error can be obtained for use by an application through the use of an EDBEngineError exception. EDBEngineError exceptions are handled in an application through the use of a try..except construct. When an EDBEngineError exception occurs, a EDBEngineError object would be created and various fields in that EDBEngineError object would be used to programmatically determine what went wrong and thus what needs to be done to correct the situation. Also, more than one error message may be generated for a given exception. This requires iterating through the multiple error messages to get needed information.

    The fields that are most pertinent to this context are:

    ErrorCount: type Integer; indicates the number of errors that are in the Errors property; counting begins at zero.

    Errors: type TDBError; a set of record-like structures that contain information about each specific error generated; each record is accessed via an index number of type Integer.

    Errors.ErrorCode: type DBIResult; indicating the BDE error code for the error in the current Errors record.

    Errors.Category: type Byte; category of the error referenced by the ErrorCode field.

    Errors.SubCode: type Byte; subcode for the value of ErrorCode.

    Errors.NativeError: type LongInt; remote error code returned from the server; if zero, the error is not a server error; SQL statement return codes appear in this field.

    Errors.Message: type TMessageStr; if the error is a server error, the server message for the error in the current Errors record; if not a server error, a BDE error message.

    In a try..except construct, the EDBEngineError object is created directly in the except section of the construct. Once created, fields may be accessed normally, or the object may be passed to another procedure for inspection of the errors. Passing the EDBEngineError object to a specialized procedure is preferred for an application to make the process more modular, reducing the amount of repeated code for parsing the object for error information. Alternately, a custom component could be created to serve this purpose, providing a set of functionality that is easily transported across applications. The example below only demonstrates creating the DBEngineError object, passing it to a procedure, and parsing the object to extract error information.

    In a try..except construct, the DBEngineError can be created with syntax
    such as that below:

    procedure TForm1.Button1Click(Sender: TObject);
    i: Integer;
    if Edit1.Text > ' ' then
    Table1.FieldByName('Number').AsInteger := StrToInt(Edit1.Text);
    on E: EDBEngineError do

    In this procedure, an attempt is made to change the value of a field in a table and then call the Post method of the corresponding TTable component.

    Only the attempt to post the change is being trapped in the try..except
    construct. If an EDBEngineError occurs, the except section of the construct is executed, which creates the EDBEngineError object (E) and then passes it to the procedure ShowError. Note that only an EDBEngineError exception is being accounted for in this construct. In a real-world situation, this would likely be accompanied by checking for other types of exceptions.

    The procedure ShowError takes the EDBEngineError, passed as a parameter, and queries the object for contained errors. In this example, information about the errors are displayed in a TMemo component. Alternately, the extracted values may never be displayed, but instead used as the basis for logic branching so the application can react to the errors. The first step in doing this is to establish the number of errors that actually occurred. This is the purpose of the ErrorCount property. This property supplies a value of type Integer that may be used to build a for loop to iterate through the errors contained in the object. Once the number of errors actually contained in the object is known, a loop can be used to visit each existing error (each represented by an Errors property record) and extract information about each error to be inserted into the TMemo component.

    procedure TForm1.ShowError(AExc: EDBEngineError);
    i: Integer;
    Memo1.Lines.Add('Number of errors: ' + IntToStr(AExc.ErrorCount));
    {Iterate through the Errors records}
    for i := 0 to AExc.ErrorCount - 1 do
    Memo1.Lines.Add('Message: ' + AExc.Errors[i].Message);
    Memo1.Lines.Add(' Category: ' +
    Memo1.Lines.Add(' Error Code: ' +
    Memo1.Lines.Add(' SubCode: ' +
    Memo1.Lines.Add(' Native Error: ' +

Sign In or Register to comment.