码迷,mamicode.com
首页 > 其他好文 > 详细

Firedac 数据连接池的应用

时间:2014-12-31 22:43:07      阅读:393      评论:0      收藏:0      [点我收藏+]

标签:

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个连接。

 

Firedac 数据连接池的应用

标签:

原文地址:http://www.cnblogs.com/Jiaojiawang/p/4196624.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!