EDatabaseError
Delphi Programming Language
Severity: ModerateWhat Does This Error Mean?
EDatabaseError is the base class for all database-related exceptions in Delphi. It is raised by database components (FireDAC, dbExpress, BDE, IBX) when a database operation fails. The specific cause can range from a connection failure and an SQL syntax error to a constraint violation or a missing table.
Affected Models
- All Delphi versions
- FireDAC
- dbExpress
- IBX
- UniDAC
- BDE
Common Causes
- A database connection failure — wrong server address, port, username, or password
- An SQL query with a syntax error or a reference to a table or column that does not exist
- A constraint violation — inserting a duplicate value into a unique key field, or violating a foreign key
- Trying to open a query or table when the connection is not active
- A type mismatch when assigning values to query parameters
How to Fix It
-
Read the full E.Message in the exception. Database errors include a detailed message from the database engine itself, which tells you exactly what went wrong.
Log or display E.Message in your error handling code — it contains the real error from Firebird, SQL Server, or whichever database you use.
-
For connection errors, verify all connection parameters: ServerName or Host, Port, DatabaseName, Username, and Password. Test the same connection in a standalone database tool like IBExpert or DBeaver.
In FireDAC, set FDConnection.LoginPrompt := False and check FDConnection.Params before calling Connect.
-
For SQL errors, copy the exact query string and test it directly in your database management tool. This gives you immediate feedback from the database engine.
Use ShowMessage(MyQuery.SQL.Text) to see the exact SQL being sent before it executes.
-
Check that the database connection is active before opening queries. Use an if FDConnection.Connected then check, or add an event handler for connection errors.
Opening a query on an inactive connection always raises EDatabaseError.
-
For constraint violations (duplicate key, foreign key), handle EDatabaseError in a try/except block and check the error message to present a friendly message to the user.
Example: if Pos('unique', LowerCase(E.Message)) > 0 then ShowMessage('This record already exists.');
When to Call a Professional
Most EDatabaseError cases are fixable yourself. The error message (in E.Message) contains the specific database error — read it carefully. For connection problems, verify your connection settings. For SQL errors, test the query directly in your database tool.
Frequently Asked Questions
How do I find out what database error code was returned?
Cast the exception to the specific component's exception class. In FireDAC, use EFDDBEngineException — it has an Errors collection with error codes and messages from the database engine. For Firebird/IBX errors, the exception message includes the error number (like -902 for connection failure).
Why does my query work in IBExpert but fail in my Delphi application?
The most common reasons are: different user permissions, different parameter types (the query uses parameters in Delphi that are not in your test), or a transaction state issue. Check that the query text matches exactly, parameters are bound correctly, and the connection has an active transaction if required.
Should I catch EDatabaseError everywhere or let it propagate?
Catch it at the highest level where you can give the user a meaningful message and decide what to do. For Firebird and similar transactional databases, also make sure you roll back the current transaction when a database error occurs. Do not silently swallow EDatabaseError — always log or display the message.