1

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.

bluish
  • 26,356
  • 27
  • 122
  • 180
Vitor Rangel
  • 363
  • 1
  • 4
  • 13
  • 1
    Since this is for school, how has your instructor told you to access the database? Surely everyone in your class has the same problem, right? – Rob Kennedy Oct 31 '11 at 20:41
  • Actually, it's a last year project. Each group chose a language and a project. My group chose Delphi and Java, but we are the only ones using Delphi. We need to show the project to the teacher tomorrow, and we can't fix this error. Anyway, we can tell our teacher tomorrow that we couldn't fix the error. – Vitor Rangel Oct 31 '11 at 21:50

4 Answers4

3

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.

bluish
  • 26,356
  • 27
  • 122
  • 180
Chris Thornton
  • 15,620
  • 5
  • 37
  • 62
  • Actually, I'm using Windows XP. This application is a Project for my School, so I don't need to worry about another OS. – Vitor Rangel Oct 31 '11 at 19:58
3

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; 
 ...
bluish
  • 26,356
  • 27
  • 122
  • 180
No'am Newman
  • 6,395
  • 5
  • 38
  • 50
  • 1
    I would start with "Unified Interbase" library here - it has native support for Firebird. BUT - it is already too late to rewrite all the program, when they lingered to the very LAST day – Arioch 'The Jan 28 '19 at 09:41
2

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.

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
  • Maybe he misses some DLLs too, but as of now his primary problem is missing dbExpress configuration on the target computer. So, his #1 priority is to read Delphi 7 documentation about how to install dbExpress library on the school computers. – Arioch 'The Jan 28 '19 at 09:45
1

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

S.FATEH
  • 451
  • 8
  • 16
  • one can write a custom factory for DBX to avoid having an ini file and registry records. But definitely not in the last day.... Also `midas.dll` should be registered (google regsvr32 or tregsrv utilities) unless one writes a custom midas dll locator factory (or using MidasLib - it is slow, but for a school project that is not a big issue) – Arioch 'The Jan 28 '19 at 09:39
  • For the record: here is a no-ini DBX factory for Delphi XE2 - it might be a starting point to write one for somewhat more recent Delphi 10.3 - or for very elder Delphi 7: https://github.com/the-Arioch/XE2fixes – Arioch 'The Jan 28 '19 at 09:45