How to connect in a firebird database in execution time?

8.7k views Asked by At

I'm having a hard time to make my code work. I want to connect to a database with my application in Delphi 7, but if I change the folder of the application, for example, if I install in another computer, my datamodule stops working. The error is:

Raised exception class EdatabaseError with message "Missing Drivername propriety"

My actual code is:

procedure TDataModule1.DataModuleCreate(Sender: TObject);
var
  conexao : TSQLConnection;
begin
   with SQLConnection1 do
    begin
        ConnectionName := 'SKY';
        DriverName := 'Interbase';
        LibraryName := 'dbexpint.dll';
        VendorLib := 'gds32.dll';
        GetDriverFunc := 'getSQLDriverINTERBASE';
        LoadParamsOnConnect := true;
        LoginPrompt := False;
        Params.Add('Database='+ExtractFilePath(Application.ExeName)+'\Banco\FLY_SKY_DESK.FDB');
        Params.Add('User_Name=SYSDBA');
        params.Add('Password=masterkey');
        Params.Add('SQLDialect=3');
        Open;
    end;
      SQLConnection1.Connected:=true;
end;

I want to connect to the database using my .exe, on any path or install location.

4

There are 4 answers

1
No'am Newman On

I faced a similar problem when I tried to write code which would open a Firebird database from a thread. The code looks like you are using the dbExpress TSQLConnection; it's much easier if you use the IB components, specifically TIBDatabase. Then your code becomes something like the following

var
 ibdb: TIBDatabase;
 qDefaults: TIBQuery;
 trans: TIBTransaction;

begin
 ibdb:= TIBDatabase.Create (nil);
 ibdb.databasename:= ExtractFilePath(Application.ExeName)+'\Banco\FLY_SKY_DESK.FDB')
 ibdb.loginprompt:= false;
 ibdb.params.add ('password=masterkey');
 ibdb.params.add ('user_name=sysdba');
 ibdb.sqldialect:= 3;
 ibdb.connected:= true;
 trans:= TIBTransaction.create (nil);
 trans.defaultdatabase:= ibdb;
 qDefaults:= TIBQuery.create (nil);
 qDefaults.database:= ibdb;
 qDefaults.transaction:= trans;
 qDefaults.sql.Add ('select * from defaults');
 qDefaults.active:= true; 
 ...
1
Chris Thornton On

If you are running Windows 7 or Vista, and install your app into the "\Program files" (either one) directory, this will not work due to folder virtualization within UAC.

You should NOT attempt to place the database within the same directory that the program is running from. You will get away with it on XP and earlier. From then on, it's a no-no.

This may not be your problem, but it definitely IS a problem.

1
Marcus Adams On

You are most likely missing the DLLs required on the target computer. You'll need to figure out which DLLs should be included with the client application and install them on the target computer. Often, simply placing the required DLLs in the same folder as the EXE will work.

I can't figure out quite what you're using since you reference Interbase and dbExpress and Firebird, but your target computer probably doesn't have the needed drivers.

2
S.FATEH On

You need to deploy:

dbxconnections.ini
dbxdrivers.ini 
dbxfb.dll 
fbclient.dll 
midas.dll {in case you used ClientDatasSet and you didn't include MidasLib into uses clause}

after deploy all those files along with your Exe than you need to update registry entry to point to locations of dbxconnections.ini and dbxdrivers.ini my version is delphi 10.3 so the registry entry are located in

HKEY_CURRENT_USER > Software > Embarcadero > BDS > 20.0 > DBExpress

Connection Registry File value is the path to dbxconnections.ini Driver Registry File value is the path to dbxdrivers.ini