如何从Delphi XE Professional IDE中访问数据库? [英] How to access databases from within Delphi XE Professional IDE?

查看:250
本文介绍了如何从Delphi XE Professional IDE中访问数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过Delphi XE Professional中的任何方式访问任何数据库。我访问数据库的意思是:


  1. 通过对象检查器中的
    组件显示活动数据库$ b当connected属性设置为
    到true

  2. 使用Data Explorer创建
    并探索数据库连接

编辑:

SORTED !!



核心问题



混淆和掩蔽子问题是:


  1. 缺少或放错的DLL。

  2. Data Explorer不完全支持dbExpress驱动程序。

  3. 2009 IDE代码中有一个错误,由 Chee-Yang Chau 发现当写入dbxFirebird驱动程序时,它限制了驱动程序的静态链接到Delphi。

  4. 使用对象检查器时,很容易导致IDE将已更改的连接参数还原为其默认值。

  5. 一些驱动程序具有不正确的默认值(例如,假设客户端dll总是gdb32.dll,而不管数据库是Interbase还是Firebird)。

  6. 版本的Interbase导致数据库通信中的一些冲突 - 工具生成的服务器名称很奇怪;并且数据库的视图取决于使用的是Interbase工具的安装。

  7. 提供的文档有不同的日期;指不同版本;因此经常出现矛盾。

END EDIT: b $ b

尝试的方法:


  1. 多个数据库

  2. 多个不同的驱动程序/组件

  3. 通过其他外部工具(如IBSQL和Flame Robin)访问数据库。

  4. 提出问题(此处
  5. 提升率(%):

环境:



$ b b


  1. 操作系统:Windows 7 Ultimate 64bit:

  2. DelphiEmbarcadero®RAD Studio XE Professional版本15.0.3953.35171

  3. 数据库:W1-V2.5.0.26074 Firebird 2.5(64位)

  4. 连接技术:dbExpress


解决方案

我现在可以编写代码来访问IDE中的Firebird。我有(有限,但足够)访问IDE中的驱动程序。具体来说,驱动程序显示在数据资源管理器中,可用于生成SQLConnection(dbExpress组件)的默认值。这些可以在对象检查器中访问和使用。需要解决下面引用的IDE错误,以确保通信参数正确。在编写数据库代码时,必须在dbExpress驱动程序的源代码中编译。



以下代码是最小的,具有最小的参数集,数据库连接:

 单位Unit2; 
interface
使用类,SqlExpr,Dialogs,dbxDevartInterbase;
var SQLConnection1:TSQLConnection;
实现
{$ R * .dfm}
begin
SQLConnection1:= TSQLConnection.Create(nil);
with SQLConnection1 do
begin
ConnectionName:='TestConnection';
DriverName:='DevartInterBase';
LibraryName:='dbexpida40.dll';
VendorLib:='fbclient.dll';
GetDriverFunc:='getSQLDriverInterBase';
Params.Clear;
Params.Add('User_Name = SYSDBA');
Params.Add('Password = masterkey');
Params.Add('Database = localhost:C:\Program Files\Firebird\Firebird_2_5\examples\empbuild\employee.fdb');
打开;
如果Connected,则ShowMessage('Connection is active');
免费;
end;
end。

解决方法,由 Bob Swart 在其中一个Codegear论坛上是:


诀窍是选择一个
ConnectionName值,然后
为驱动程序属性
和所有其他属性(如
LibraryName,VendorLib和
GetDriverFunc)分配一个值。



然后,如果需要,更改
驱动程序
属性的子属性,最后清除驱动程序的名称
属性。



这会将所有更改保留在
的Params列表中(如果您愿意,也可以手动编辑
)。



注意:保留ConnectionName设置 -
如果清除那个参数,
将被重新清除。



现在你可以编译你的应用程序
并部署它,而不需要
dbxdrivers.exe或dbxconnections.ini
(但你需要部署DLL
指定在LibraryName和
VendorLib中,当然)。



还要确保将LoginPrompt设置为
False,并将LoadParamsOnConnect
设置为False。



I cannot access ANY database by ANY means from within Delphi XE Professional. What I mean by accessing the data base is:

  1. having the live database appear via components in the Object Inspector, when the connected property is set to true
  2. using the Data Explorer to create and explore database connections

EDIT:
SORTED !!

The core problem is that communication into the database, including specifically the communication generated by the IDE and any code built using the drivers was problematic.

Confounding and masking sub-issues were:

  1. Missing or misplaced DLLs.
  2. The Data Explorer does not fully support dbExpress drivers.
  3. There is a bug within the 2009 IDE code, found by Chee-Yang Chau when writing the dbxFirebird driver, which limits static linking of drivers into Delphi. It is not known if this bug extends to 2010 or XE.
  4. When using the Object Inspector, it is easy to cause the IDE to revert changed connection parameters to their default values.
  5. Some drivers had incorrect default values (eg assuming the client dll was always gdb32.dll irrespective of whether the database was Interbase or Firebird).
  6. Installation of two versions of Interbase led to some clashes in database communication - server names generated by the tools were odd; and the view of the databases depended on which installation of the Interbase tools were used.
  7. The documentation available is of varying dates; refers to different versions; and as a result often appears contradictory.

END EDIT:

Approaches tried:

  1. Multiple databases
  2. Multiple different drivers/components
  3. Accessing the database through other external tools, such as IBSQL and Flame Robin.
  4. Raising questions (here and here) on SO.
  5. Raising questions on the support forums for Firebird, Embarcardo, and Flame Robin.

Environment:

  1. OS: Windows 7 Ultimate 64bit:
  2. Delphi Embarcadero® RAD Studio XE Professional Version 15.0.3953.35171
  3. Database: W1-V2.5.0.26074 Firebird 2.5 (64 bit)
  4. Connection technology: dbExpress

解决方案

I can now write code to access Firebird within the IDE. I have (limited, but sufficient) access to the drivers within the IDE. Specifically, the drivers appear in the Data Explorer, which can be used to generate default values for the SQLConnection (dbExpress component). These can be accessed and used within the Object Inspector. The workaround to the IDE bug quoted below is necessary to ensure the communication parameters are correct. When writing database code, it is necessary to compile in the source for the dbExpress driver.

The following code is the minimum, with minimum parameter set, necessary to establish and test a database connection:

unit Unit2;
interface
uses Classes, SqlExpr, Dialogs, dbxDevartInterbase;
var SQLConnection1 : TSQLConnection;
implementation
{$R *.dfm}
  begin
    SQLConnection1 := TSQLConnection.Create(nil);
    with SQLConnection1 do
    begin
      ConnectionName := 'TestConnection';
      DriverName := 'DevartInterBase';
      LibraryName := 'dbexpida40.dll';
      VendorLib := 'fbclient.dll';
      GetDriverFunc := 'getSQLDriverInterBase';
      Params.Clear;
      Params.Add('User_Name=SYSDBA');
      Params.Add('Password=masterkey');
      Params.Add('Database=localhost:C:\Program Files\Firebird\Firebird_2_5\examples\empbuild\employee.fdb');
      Open;
      If Connected then ShowMessage('Connection is active');
      Free;
    end;
  end.

The workaround, courtesy of Bob Swart on one of the Codegear forums is:

The trick is to select a ConnectionName value, which will then assign a value to the Driver property and all other properties like LibraryName, VendorLib and GetDriverFunc.

Then, make changes - if needed - to the subproperties of the Driver property, and finally clear the name of the Driver property.

This will leave all your changes in the Params list (which you can also manually edit if you wish).

Note: leave the ConnectionName set - if you clear that one, the parameters will be cleared again.

Now you can compile your application and deploy it without the need for dbxdrivers.exe or dbxconnections.ini (but you need to deploy the DLLs specified in the LibraryName and VendorLib, of course).

Also make sure to set LoginPrompt to False and leave LoadParamsOnConnect set to False, too.

这篇关于如何从Delphi XE Professional IDE中访问数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆