连接到 D2010 上嵌入的 Firebird
我从 http://sites.google.com/site/dbxfirebird/ 我已经能够编译“测试连接”项目并让它运行。我将它指向我的测试数据库,如下所示:
procedure TMainForm.Button1Click(Sender: TObject);
var C: TSQLConnection;
begin
C := TSQLConnection.Create(Self);
try
C.DriverName := 'FirebirdConnection';
C.Params.Add('User_Name=SYSDBA');
C.Params.Add('Password=masterkey');
C.Params.Add('Database=C:\fbtest\test.fdb');
C.Open;
if C.Connected then
ShowMessage('Connection is active')
finally
C.Free;
end;
end;
当我运行它时,它工作正常。但是当我将完全相同的代码放入不同的项目中时,它不起作用。我已将 fbclient.dll(Firebird 嵌入式驱动程序 DLL,重命名为 fbclient)、其所有依赖项和 dbxdrivers.ini 文件复制到与项目的 EXE 运行所在的同一文件夹中。我看不出任何原因这不应该工作,但是对 .Open 的调用失败并显示:
项目 Project1.exe 引发异常 类 TDBXError 带有消息“未知” 驱动程序:FirebirdConnection'。
同样,这是对 Open 的调用。对 DriverName 的分配工作得很好。以前有人见过这个问题吗?为什么完全相同的代码在测试项目中可以工作,但不同的代码却不能工作,有什么方法可以修复它吗?
I downloaded the Firebird DBX driver from http://sites.google.com/site/dbxfirebird/ and I've been able to compile the "Test Connection" project and get it to run. I pointed it to my test DB like so:
procedure TMainForm.Button1Click(Sender: TObject);
var C: TSQLConnection;
begin
C := TSQLConnection.Create(Self);
try
C.DriverName := 'FirebirdConnection';
C.Params.Add('User_Name=SYSDBA');
C.Params.Add('Password=masterkey');
C.Params.Add('Database=C:\fbtest\test.fdb');
C.Open;
if C.Connected then
ShowMessage('Connection is active')
finally
C.Free;
end;
end;
When I run it, it works fine. But when I put that exact same code in a different project, it doesn't work. I've copied the fbclient.dll (Firebird embedded driver DLL, renamed to fbclient), all of its dependencies, and the dbxdrivers.ini file to the same folder as the project's EXE is running in. I can't see any reason why this shouldn't work, but the call to .Open fails with:
Project Project1.exe raised exception
class TDBXError with message 'Unknown
driver: FirebirdConnection'.
Again, this is on the call to Open. The assignment to DriverName works just fine. Has anyone seen this problem before? Why does the exact same code work in the test project but not a different one, and is there any way I can fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现了问题。用于设置数据库驱动程序的加载类必须在 DBXDynalink.pas 的初始化部分中注册。测试项目在其 uses 子句中包含了 DBXDynalink,而我的项目则没有。我把它放进去,现在它可以工作了。
I found the problem. A loading class to set up the database driver had to be registered in the initialization section of DBXDynalink.pas. The test project included DBXDynalink in its uses clause, where mine didn't. I put that in and now it works.
当您没有将相应的 DBX 驱动程序单元添加到您的使用列表中时,通常会发生此错误。尝试将 DBXFirebird 添加到您的使用列表中。
This error generally occurs when you don't add the respective DBX driver unit to your uses list. Try adding DBXFirebird to your uses list.
只是改变
C.DriverName := 'FirebirdConnection';
到
C.DriverName := 'Firebird';
并且会起作用!
Just change
C.DriverName := 'FirebirdConnection';
to
C.DriverName := 'Firebird';
and will work!