我的应用程序有一个设计时间
TFDConnection
和 TFDPhysFBDriverLink
作为源连接。这可能会也可能不会在 Firebird 嵌入模式下打开(如果是这样,则设置 FDPhysFBDriverLink.VendorLib := 'fbembed.dll'
(32 位))。
我创建了一个运行时目标
TFDConnection
,它必须使用嵌入式Firebird,因为我们不知道Firebird是否安装在PC上(我们的安装提供fbembed.dll
)。
我该如何设置?在运行时,我可以创建另一个
TFDPhysFBDriverLink
并设置其 VendorLib,但 FireDAC 如何知道其关联的连接是什么?或者我可以在应用程序中只使用一个FDPhysFBDriverLink
吗?
这是我正在转换的旧代码,使用 DirectSQL,这也用于设置一些神奇的
SDFib.SqlApiDLL := FBEMBED
属性,据说该属性仅适用于目标数据库。
您遇到的最糟糕的情况是安装了 Firebird,因此一个连接连接到已安装的服务器实例,而另一个连接连接到嵌入式服务器实例。因为拥有一个物理驱动程序对象就足够了,但拥有更多也没有问题。
因此,将一个 TFDPhysFBDriverLink 放在表单或数据模块上,并将其 DriverID 属性设置为唯一名称(不用作任何驱动程序的基本驱动程序 ID),并将其标记为 Embedded (如果您此时指定 VendorLib,则没有实际意义,但您可以使用它来识别驱动程序;FireDAC 使用此属性仅用于决定应加载哪个默认库)。
然后,对于一个连接,使用您定义的 DriverID,而对于另一个连接,则使用其 BaseDriverID 回退到默认 Firebird 驱动程序设置(我省略了此任务不必要的设置):
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 }
但我更喜欢有两个单独的驱动程序对象,一个用于已安装的服务器(具有默认设置,如基本驱动程序),另一个用于嵌入式服务器。例如:
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 }
谢谢!一旦打开其中一个驱动程序,我就无法切换驱动程序,现在我的应用程序可以正确切换。