如何在执行时连接firebird数据库?

发布于 2024-12-13 00:11:20 字数 923 浏览 4 评论 0原文

我很难让我的代码正常工作。我想使用 Delphi 7 中的应用程序连接到数据库,但是如果我更改应用程序的文件夹,例如,如果我安装在另一台计算机上,我的数据模块将停止工作。错误是:

引发异常类 EdatabaseError 并显示消息“缺少驱动程序名称属性”

我的实际代码是:

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;

我想在任何路径或安装位置使用我的 .exe 连接到数据库。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

星光不落少年眉 2024-12-20 00:11:20

如果您运行的是 Windows 7 或 Vista,并将应用程序安装到“\Program files”(任一)目录中,则由于 UAC 中的文件夹虚拟化,此操作将不起作用。

您不应尝试将数据库放置在程序运行所在的同一目录中。在 XP 及更早版本上,您将不会受到影响。从那时起,这是一个禁忌。

这可能不是你的问题,但它绝对是一个问题。

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.

め可乐爱微笑 2024-12-20 00:11:20

当我尝试编写从线程打开 Firebird 数据库的代码时,我遇到了类似的问题。该代码看起来像您正在使用 dbExpress TSQLConnection;如果您使用 IB 组件,特别是 TIBDatabase,就会容易得多。然后你的代码就变成类似下面的样子

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; 
 ...

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; 
 ...
完美的未来在梦里 2024-12-20 00:11:20

您很可能缺少目标计算机上所需的 DLL。您需要确定客户端应用程序中应包含哪些 DLL,并将它们安装在目标计算机上。通常,只需将所需的 DLL 放在与 EXE 相同的文件夹中即可。

我不太清楚你在使用什么,因为你引用了 Interbase、dbExpress 和 Firebird,但你的目标计算机可能没有所需的驱动程序。

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.

新人笑 2024-12-20 00:11:20

您需要部署:

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

将所有这些文件与您的 Exe 一起部署后,您需要更新注册表项以指向 dbxconnections.ini 和 dbxdrivers.ini 的位置,我的版本是delphi 10.3,因此注册表项位于

HKEY_CURRENT_USER > Software > Embarcadero > BDS > 20.0 > DBExpress

连接注册表文件中,值是dbxconnections.ini的路径
驱动程序注册表文件值是dbxdrivers.ini的路径

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文