美文网首页
FIREDAC连接池配置

FIREDAC连接池配置

作者: abctel | 来源:发表于2018-11-01 11:08 被阅读0次

    原文在Delphi XE7 下测试通过

    • 需要的控件
    fdphysrcldrvrlnk1: TFDPhysOracleDriverLink;
    fdgxwtcrsr1: TFDGUIxWaitCursor;
    fdphysmysqldrvrlnk1: TFDPhysMySQLDriverLink;
    
    • 需要的变量
    var
      adm:TFDManager;
      oParams: TStrings;
    
    • 示例代码
    begin
      adm:=TFDManager.Create(nil);
      oParams := TStringList.Create;
      try
        oParams.Add('Database=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ip)(PORT=1521))(CONNECT_DATA=(SERVER=dedicated)(SERVICE_NAME=sid)))');
        oParams.Add('User_Name=dbuser');
        oParams.Add('Password=dbpwd');
        oParams.Add('Pooled=True');
        oParams.Add('CleanupTimeout=0');
        oParams.Add('ExpireTimeout=0');
        oParams.Add('PoolMaximumItems=20');
        adm.AddConnectionDef('Oracle_Pooled', 'Ora', oParams);
        oParams.Clear;
        oParams.Add('Server=ip');
        oParams.Add('Port=port');
        oParams.Add('Database=dbname');
        oParams.Add('CharacterSet=utf8');
        oParams.Add('User_Name=dbuser');
        oParams.Add('Password=dbpwd');
        oParams.Add('Pooled=True');
        oParams.Add('PoolMaximumItems=10');
        adm.AddConnectionDef('Mysql_Pooled', 'Mysql', oParams);
      finally
        oParams.Free;
      end;
    end;
    
    • 客户端代码
    procedure TConnectThread.Execute;
    var
      oConn:  TFDConnection;
      oQuery: TFDQuery;
      i: Integer;
    begin
      oConn  := TFDConnection.Create(nil);
      oQuery := TFDQuery.Create(nil);
      try
        oQuery.Connection := oConn;
        oConn.ConnectionDefName := 'Oracle_Pooled';
        for i := 1 to 5 do begin
          oQuery.SQL.Text := 'select count(1) from table';
          oQuery.Open;
          oConn.Close;
          Synchronize(FForm.Executed);
        end;
      finally
        oConn.Free;
        oQuery.Free;
      end;
    end;
    

    原作者:rznice
    原文:https://blog.csdn.net/rznice/article/details/41486093

    相关文章

      网友评论

          本文标题:FIREDAC连接池配置

          本文链接:https://www.haomeiwen.com/subject/nlwtxqtx.html