设置第二个TFDPhysFBDriverLink-可能和必要吗? [英] Setting up a second TFDPhysFBDriverLink - possible and necessary?

查看:137
本文介绍了设置第二个TFDPhysFBDriverLink-可能和必要吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的设计时间为 TFDConnection TFDPhysFBDriverLink 作为源连接。这可能会或可能不会在Firebird嵌入式模式中打开(如果已打开,则设置 FDPhysFBDriverLink.VendorLib:='fbembed.dll'(32位))。

My application has a design time TFDConnection and TFDPhysFBDriverLink as source connection. This may or may not be opened in Firebird embedded mode (if so, FDPhysFBDriverLink.VendorLib := 'fbembed.dll' is set (32 bits)).

我创建了运行时目标 TFDConnection ,其中必须使用嵌入式Firebird,因为我们不知道是否Firebird已安装在PC上(我们的安装程序提供 fbembed.dll )。

I create a run-time target TFDConnection which must use embedded Firebird because we do not know if Firebird is installed on the PC (our setup supplies fbembed.dll).

如何设置?在运行时,我可以创建另一个 TFDPhysFBDriverLink 并设置其VendorLib,但是FireDAC如何知道其关联的连接是什么?还是我只能在应用程序中使用一个 FDPhysFBDriverLink

How do I set this up? At runtime I can create another TFDPhysFBDriverLink and set its VendorLib, but how does FireDAC know what its associated connection is? Or can I use only one FDPhysFBDriverLink in the application?

这是我正在转换的旧代码,使用<一个href = https://sourceforge.net/projects/directsql/ rel = nofollow noreferrer> DirectSQL ,它还用于设置一些魔术 SDFib.SqlApiDLL:= FBEMBED 属性,该属性仅适用于目标数据库。

This is old code I'm converting, using DirectSQL, and this also used to set some magic SDFib.SqlApiDLL := FBEMBED property, which supposedly worked for the target database only.

推荐答案

在您的情况下,最糟糕的情况是Firebird已安装,因此一个连接连接到已安装的服务器实例,而另一个连接到嵌入式服务器实例。这样就可以拥有一个物理驱动程序对象,但是拥有更多驱动程序对象也没有问题。

Worst case in your situation is that Firebird is installed, so one connection connects to that installed server instance whilst another to the embedded one. For that is enough to have one physical driver object, but there's no problem having more.

因此,删除一个 TFDPhysFBDriverLink 并设置其 DriverID 属性为唯一名称(未用作基本驱动程序任何驱动程序的ID),并将其标记为 嵌入 (如果您指定 VendorLib ,但您可以使用它来识别驱动程序; FireDAC使用此p

So, drop one TFDPhysFBDriverLink on a form or datamodule and setup its DriverID property to a unique name (that is not used as base driver ID for any driver), and mark it as Embedded (that has no practical meaning in case when you specify VendorLib at this time, but you can use it to identify the driver; FireDAC uses this property only for decision which default library should be loaded).

然后对于一个连接使用 DriverID ,对于另一个,您可以使用其 BaseDriverID (我省略了不必要的设置此任务):

Then for one connection use DriverID that you defined and for the other one use fallback to default Firebird driver settings by using its BaseDriverID (I've omitted settings unecessary for this task):

FDPhysFBDriverLink1.DriverID := 'FBEmbedded'; { ← ID not used by any BaseDriverID }
FDPhysFBDriverLink1.Embedded := True; { ← not mandatory when VendorLib is specified }
FDPhysFBDriverLink1.VendorLib := 'C:\fbembed.dll'; { ← client library file name }

FDConnection1.Params.DriverID := 'FB'; { ← driver's BaseDriverID }
FDConnection1.Open; { ← this will connect to the installed server }

FDConnection2.Params.DriverID := 'FBEmbedded'; { ← driver's DriverID }
FDConnection2.Open; { ← this will connect to the embedded server }

但我希望有两个单独的驱动程序对象,一个用于已安装的服务器(具有默认设置,例如基本驱动程序具有),而一个用于嵌入式服务器。例如:

But I would prefer having two separate driver objects, one for installed server (with default settings, like base driver has) and one for embedded server. For example:

FDPhysFBDriverLink1.DriverID := 'FBEmbedded'; { ← ID not used by any BaseDriverID }
FDPhysFBDriverLink1.Embedded := True; { ← not mandatory when VendorLib is specified }
FDPhysFBDriverLink1.VendorLib := 'C:\fbembed.dll'; { ← client library file name }

FDPhysFBDriverLink2.DriverID := 'FBInstalled'; { ← ID not used by any BaseDriverID }

FDConnection1.Params.DriverID := 'FBEmbedded'; { ← driver 1 DriverID }
FDConnection1.Open; { ← this will connect to the embedded server }

FDConnection2.Params.DriverID := 'FBInstalled'; { ← driver 2 DriverID }
FDConnection2.Open; { ← this will connect to the installed server }

这篇关于设置第二个TFDPhysFBDriverLink-可能和必要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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