如何在执行时连接firebird数据库?
我很难让我的代码正常工作。我想使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您运行的是 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.
当我尝试编写从线程打开 Firebird 数据库的代码时,我遇到了类似的问题。该代码看起来像您正在使用 dbExpress
TSQLConnection
;如果您使用 IB 组件,特别是TIBDatabase
,就会容易得多。然后你的代码就变成类似下面的样子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, specificallyTIBDatabase
. Then your code becomes something like the following您很可能缺少目标计算机上所需的 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.
您需要部署:
将所有这些文件与您的 Exe 一起部署后,您需要更新注册表项以指向 dbxconnections.ini 和 dbxdrivers.ini 的位置,我的版本是delphi 10.3,因此注册表项位于
连接注册表文件
中,值是dbxconnections.ini
的路径驱动程序注册表文件
值是dbxdrivers.ini
的路径You need to deploy:
after deploy all those files along with your Exe than you need to update registry entry to point to locations of
dbxconnections.ini
anddbxdrivers.ini
my version is delphi 10.3 so the registry entry are located inConnection Registry File
value is the path todbxconnections.ini
Driver Registry File
value is the path todbxdrivers.ini