Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access databases from within Delphi XE Professional IDE?

I cannot access ANY database by ANY means from within Delphi XE Professional. What I mean by accessing the data base is:

  1. having the live database appear via components in the Object Inspector, when the connected property is set to true
  2. using the Data Explorer to create and explore database connections

EDIT:
SORTED !!

The core problem is that communication into the database, including specifically the communication generated by the IDE and any code built using the drivers was problematic.

Confounding and masking sub-issues were:

  1. Missing or misplaced DLLs.
  2. The Data Explorer does not fully support dbExpress drivers.
  3. There is a bug within the 2009 IDE code, found by Chee-Yang Chau when writing the dbxFirebird driver, which limits static linking of drivers into Delphi. It is not known if this bug extends to 2010 or XE.
  4. When using the Object Inspector, it is easy to cause the IDE to revert changed connection parameters to their default values.
  5. Some drivers had incorrect default values (eg assuming the client dll was always gdb32.dll irrespective of whether the database was Interbase or Firebird).
  6. Installation of two versions of Interbase led to some clashes in database communication - server names generated by the tools were odd; and the view of the databases depended on which installation of the Interbase tools were used.
  7. The documentation available is of varying dates; refers to different versions; and as a result often appears contradictory.

END EDIT:

Approaches tried:

  1. Multiple databases
  2. Multiple different drivers/components
  3. Accessing the database through other external tools, such as IBSQL and Flame Robin.
  4. Raising questions (here and here) on SO.
  5. Raising questions on the support forums for Firebird, Embarcardo, and Flame Robin.

Environment:

  1. OS: Windows 7 Ultimate 64bit:
  2. Delphi Embarcadero® RAD Studio XE Professional Version 15.0.3953.35171
  3. Database: W1-V2.5.0.26074 Firebird 2.5 (64 bit)
  4. Connection technology: dbExpress
like image 415
Chris Walton Avatar asked Feb 25 '23 10:02

Chris Walton


2 Answers

Delphi Professional does not support Firebird with the native dbExpress drivers that come with Delphi. You need the Enterprise or Architect version of Delphi in order for the native firebird dbExpress driver to work.

I have Delphi 2010 Professional. I didn't want to spend the extra money on the E or A version and I failed to read the feature matrix to see that the Firebird dbExpress driver is not available with the Pro version.

I have found a few really nice videos that show how to connect to Firebird using Delphi. However, when I tried to follow along with my Professonal version nothing worked.

Shame on me and more shame on Embarcadero for touting that Delphi supports Firebird in big bold print but not mentioning that you need the Enterprise or Architect version except in the tiny fine print.

like image 91
Michael Riley - AKA Gunny Avatar answered Feb 26 '23 23:02

Michael Riley - AKA Gunny


I can now write code to access Firebird within the IDE. I have (limited, but sufficient) access to the drivers within the IDE. Specifically, the drivers appear in the Data Explorer, which can be used to generate default values for the SQLConnection (dbExpress component). These can be accessed and used within the Object Inspector. The workaround to the IDE bug quoted below is necessary to ensure the communication parameters are correct. When writing database code, it is necessary to compile in the source for the dbExpress driver.

The following code is the minimum, with minimum parameter set, necessary to establish and test a database connection:

unit Unit2;
interface
uses Classes, SqlExpr, Dialogs, dbxDevartInterbase;
var SQLConnection1 : TSQLConnection;
implementation
{$R *.dfm}
  begin
    SQLConnection1 := TSQLConnection.Create(nil);
    with SQLConnection1 do
    begin
      ConnectionName := 'TestConnection';
      DriverName := 'DevartInterBase';
      LibraryName := 'dbexpida40.dll';
      VendorLib := 'fbclient.dll';
      GetDriverFunc := 'getSQLDriverInterBase';
      Params.Clear;
      Params.Add('User_Name=SYSDBA');
      Params.Add('Password=masterkey');
      Params.Add('Database=localhost:C:\Program Files\Firebird\Firebird_2_5\examples\empbuild\employee.fdb');
      Open;
      If Connected then ShowMessage('Connection is active');
      Free;
    end;
  end.

The workaround, courtesy of Bob Swart on one of the Codegear forums is:

The trick is to select a ConnectionName value, which will then assign a value to the Driver property and all other properties like LibraryName, VendorLib and GetDriverFunc.

Then, make changes - if needed - to the subproperties of the Driver property, and finally clear the name of the Driver property.

This will leave all your changes in the Params list (which you can also manually edit if you wish).

Note: leave the ConnectionName set - if you clear that one, the parameters will be cleared again.

Now you can compile your application and deploy it without the need for dbxdrivers.exe or dbxconnections.ini (but you need to deploy the DLLs specified in the LibraryName and VendorLib, of course).

Also make sure to set LoginPrompt to False and leave LoadParamsOnConnect set to False, too.

like image 41
Chris Walton Avatar answered Feb 26 '23 23:02

Chris Walton