procedure TForm2.Button1Click(Sender: TObject);
begin
  if not FDConnection1.Connected then
    FDConnection1.Connected := True;
//  FDQuery1.SQL.Text := 'select getdate()';
  FDQuery1.Open('select getdate()');
  Caption := FDQuery1.Fields[0].AsString;
  //FDQuery1.Close;
  FDConnection1.Connected := False;
end;

procedure TForm2.FormCreate(Sender: TObject);
var
  Def: IFDStanConnectionDef;
begin
  Def := FDManager1.ConnectionDefs.FindConnectionDef('PoolTest');
  if Def=nil then
    Def := FDManager1.ConnectionDefs.AddConnectionDef;
  Def.Name := 'PoolTest';
  Def.Params.DriverID := 'mssql';
  Def.Params.Values['Server'] := 'JJW-PC';
  Def.Params.Database := 'TJZFDB';
  Def.Params.UserName := 'sa';
  Def.Params.Password := 'Sa12345';
  Def.Params.Pooled := True;
  Def.MarkPersistent;
  Def.Apply;

  FDConnection1.ConnectionDefName := 'PoolTest';
end;

经测试,动态添加连接池在第一次里有延迟,第二次就很多了,事件探查器中发现,多次点击button,最多只有2个连接。

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2022-01-09
  • 2021-04-19
  • 2021-11-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案