• 使用Unidac内置连接池


    第一步:

       放一个TUniconnection并设置相关属性

    之后直接使用TUniconnection对象即可

    跟踪unidac源码uni单元1540行中可以看到

    Connect方法调用CreateIConnection

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    procedure TUniConnection.CreateIConnection;
    var
      Connection: TCRConnection;
      ConnectionParameters: TCRConnectionParameters;
     
      procedure SetSpecificObjectProps(SetAllProps: boolean);
      begin
        FProvider.SetObjectProps(Connection, FSpecificOptions.Values, SetAllProps);
        FSpecificOptions.IsModified := False;
      end;
     
    begin
      CheckProvider;
     
      Connection := FIConnection;
     
      if Connection = nil then begin
       <span style="color: #ff0000;"><strong> if Pooling and FProvider.IsPoolingSupported then begin</strong></span>
          ConnectionParameters := FProvider.GetConnectionParametersClass.Create;
          try
            ConnectionParameters.MinPoolSize := PoolingOptions.MinPoolSize;
            ConnectionParameters.MaxPoolSize := PoolingOptions.MaxPoolSize;
            ConnectionParameters.ConnectionLifeTime := PoolingOptions.ConnectionLifetime;
            ConnectionParameters.Validate := PoolingOptions.Validate;
            ConnectionParameters.Username := Username;
            ConnectionParameters.Password := Password;
            ConnectionParameters.Server := Server;
            ConnectionParameters.IOHandler := FIOHandler;
            ConnectionParameters.OnError := DoError;
            if FProvider.IsDatabaseSupported then //upd1
              ConnectionParameters.SetProp(prDatabase, FDatabase);
            if FProvider.IsPortSupported then
              ConnectionParameters.SetProp(prPort, Port);
     
            FProvider.SetObjectProps(ConnectionParameters, SpecificOptions, True);
     
          <span style="color: #ff0000;">  Connection := FProvider.GetConnectionPoolingManagerClass.GetConnection(
              ConnectionParameters, TUniSQLMonitor);</span>
          finally
            ConnectionParameters.Free;
          end;
        end
        else begin
          Connection := GetIConnectionClass.Create;
          Connection.IOHandler := FIOHandler;
          if FProvider.IsDatabaseSupported then
            Connection.SetProp(prDatabase, FDatabase);
          if FProvider.IsPortSupported then
            Connection.SetProp(prPort, Port);
        end;
     
        Connection.SetProp(prDisconnectedMode, Options.DisconnectedMode);
        Connection.SetProp(prEnableBCD, Options.EnableBCD);
      {$IFDEF VER6P}
      {$IFNDEF FPC}
        Connection.SetProp(prEnableFMTBCD, Options.EnableFMTBCD);
      {$ENDIF}
      {$ENDIF}
        Connection.SetProp(prDefaultSortType, Variant(Options.DefaultSortType));
        // if connection is just created we need to set all options
        SetSpecificObjectProps(True);
     
        SetIConnection(Connection);
      end;
     
      if FSpecificOptions.IsModified then
        SetSpecificObjectProps(False);
    end;

    http://www.cnblogs.com/pengshaomin/p/4126662.html

  • 相关阅读:
    利用matplotlib进行数据可视化
    《操作系统》课程笔记(Ch11-文件系统实现)
    《操作系统》课程笔记(Ch10-文件系统)
    《数据库原理》课程笔记 (Ch06-查询处理和优化)
    《计算机网络》课程笔记 (Ch05-网络层:控制平面)
    《计算机网络》课程笔记 (Ch04-网络层:数据平面)
    《计算机网络》课程笔记 (Ch03-运输层)
    东南大学《软件测试》课程复习笔记
    《数据库原理》课程笔记 (Ch05-数据库存储结构)
    《操作系统》课程笔记(Ch09-虚拟内存)
  • 原文地址:https://www.cnblogs.com/findumars/p/5321258.html
Copyright © 2020-2023  润新知