FIREDAC接続プール構成

1882 ワード

以下delphi XE 7でテストする
    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;