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: 

  • 相关阅读:
    PL/SQL注册码
    分页sql
    js获取url值
    C语言中的bool类型 stdbool.h
    语音朗读小程序
    50. Pow(x, n)
    二维数组旋转
    用一位数组代替二维数组作为形参使用
    单链表排序——交换数据成员
    C++重载输入流、输出流运算符
  • 原文地址:https://www.cnblogs.com/cb168/p/4627476.html
Copyright © 2011-2022 走看看