English 中文(简体)
如何在执行时连接firebird数据库?
原标题:How to connect in a firebird database in execution time?

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

引发异常类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)+ BancoFLY_SKY_DESK.FDB );
        Params.Add( User_Name=SYSDBA );
        params.Add( Password=masterkey );
        Params.Add( SQLDialect=3 );
        Open;
    end;
      SQLConnection1.Connected:=true;
end;

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

问题回答

如果你运行的是Windows7或Vista,并将应用程序安装到“程序文件”(任意一个)目录中,由于UAC中的文件夹虚拟化,这将不起作用。

您不应该试图将数据库放在程序运行的同一目录中。您将在XP及更早版本中逃脱惩罚。从那时起,这是一个禁忌。

这可能不是你的问题,但肯定是个问题。

当我试图编写从线程打开Firebird数据库的代码时,我也遇到了类似的问题。该代码看起来像是在使用dbExpressTSQLConnection;如果使用IB组件,特别是TIBDatabase,则会容易得多。然后您的代码变成如下所示

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

begin
 ibdb:= TIBDatabase.Create (nil);
 ibdb.databasename:= ExtractFilePath(Application.ExeName)+ BancoFLY_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; 
 ...

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

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

您需要部署:

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.inidbxdrivers.ini的位置,我的版本是Delphi10.3,因此注册表项位于

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





相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签