zoukankan      html  css  js  c++  java
  • FilreDAC DLL共享数据连接

    D:UsersPublicDocumentsEmbarcaderoStudio16.0SamplesObject PascalDatabaseFireDACSamplesComp LayerTFDConnectionDLL_Sharing

    FDConnection1.CliHandle

    FDConnection1.SharedCliHandle := ACliHandle;

    CLI handle for connection sharing.

    The CliHandle property returns a DBMS Call Level Interface connection handle. This value can be assigned to another TFDCustomConnection object's SharedCliHandle property. This is useful to transfer a connection from an application into a DLL. See DLL Development

    After setting Connected to True for the DLL connection, both connections will share the same physical DBMS connection. This connection must be closed after all other connections that share the same CLI handle. 

    CLI handle shared with other connections.

    Use SharedCliHandle to set a shared DBMS Call Level Interface connection handle returned by another connection's CliHandle property. This is useful to transfer the connection from an application into a DLL (see DLL Development).

    Note: A connection cannot be shared with another process, as the sharing works only inside the same address space.

    After setting Connected to True for this connection, it will use the same physical DBMS connection or session as the other connection, and it will share the same transaction state. 

    After setting Connected to False, this DLL connection will not release the connection resources to the DBMC client. The application connection is responsible for resources releasing. Because of that, the application connection must be closed after closing all the sharing connections. 

    DLL Development (FireDAC)

    From RAD Studio
     

    Go Up to Working with Connections (FireDAC)


    This topic describes how to use FireDAC in the dynamic loading libraries.

    Contents

    General

    FireDAC may be used in a DLL as in a normal application. However, developers must be aware of two techniques, specific to DLL development.

    Connection Sharing Between an Application and a DLL

    When a connection must be transferred from an application to the DLL, the application should not transfer the TFDCustomConnection object, because this may lead to AV errors and other issues. This is not an issue of FireDAC. It is due to the Delphi RTL / RTTI limitations. Note that a connection cannot be shared with another process, because the sharing works only inside the same address space.

    To transfer a connection between an application and a DLL, the application should transfer the TFDCustomConnection.CliHandle property value to the DLL. Here the handle must be assigned to the TFDCustomConnection.SharedCliHandle property.

    After the TFDCustomConnection.SharedCliHandle is assigned, the DLL connection can be activated by setting Connected to True. Note that there is no need to set up a connection definition, including DriverID. Then, the connection can be used as a normal database connection. Finally, it can be closed by setting Connected to False. That does not close the physical connection, therefore the application connection remains active.

    The application connection does not track state changes performed by the DLL. Therefore, the DLL should preserve the same transaction state as it had before the DLL call. It is indicated not to handle transactions in a DLL, change the transaction isolation level and other settings in a DLL.

    Also, setting SharedCliHandle does not transfer any of the option values from an application to a DLL connection object. The DLL connection options can be set similar to the application connection options.

    For example, the DLL code: 

  • 相关阅读:
    数据仓库系列之ETL过程和ETL工具
    大数据从入门到精通
    Mysql误删表中数据与误删表的恢复方法(转)
    Vscode 小白使用介绍
    Window 通过cmd查看端口占用,杀死进程方法
    Python基础教程,Python入门教程(非常详细)
    tuxedo安装与配置入门
    Win10系统Ping端口及利用telnet命令Ping 端口
    Tuxedo 介绍
    hibernate框架的简单入门
  • 原文地址:https://www.cnblogs.com/cb168/p/4627476.html
Copyright © 2011-2022 走看看