在开发Datasnap三层中,使用FireDac 连接  MSSQL数据库。

实现过程如下:

1、在ServerMethods 单元中放入 FDManager、FDPhysMSSQLDriverLink1、FDGUIxWaitCursor1等控件。

2、自定义过程:

  private
var
oParams: TStrings;
procedure TSrvMethods.SetupFDManager;    //加载数据库链接信息。
begin
//*****初始化*****
oParams := TStringList.Create;
//********* 连接池
oParams.Add('DriverID=MSSQL');
//oParams.Add('CharacterSet=utf8');
oParams.Add('Server=192.168.1.199');
//oParams.Add('Port=3306');
oParams.Add('Database=DSCSYS');
oParams.Add('User_Name=sa');
oParams.Add('Password=');
// 毫秒
oParams.Add('POOL_CleanupTimeout=36000');
// 毫秒
oParams.Add('POOL_ExpireTimeout=600000');
//最多连接数
oParams.Add('POOL_MaximumItems=60');
oParams.Add('Pooled=True');
//*******
FDManager.Close;
FDManager.AddConnectionDef('MSSQL_DSCSYS', 'MSSQL', oParams);
try
FDManager.Active := True;
except
on E: Exception do
begin
frmMain.Log.Error(e.Message, 'Error');
end;
end;
end;

3、在 Create 事件中:

procedure TSrvMethods.DSServerModuleCreate(Sender: TObject);
begin
SetupFDManager; // 加载数据库链接
end;

4、在查询使用中,动态生成FDConnection,设置Connected为true 就是  从连接池中取一个连接;具体代码如下

function TSrvMethods.QueryData(SQLStr: string): string;
var
fdqry1: TFDQuery;
mConn: TFDConnection;
begin
try
//***动态创建,用完释放;
mConn := TFDConnection.Create(nil);
mConn.ConnectionDefName := 'MSSQL_Conn';
mConn.Connected := true;
fdqry1 := TFDQuery.Create(nil);
try
fdqry1.Close;
fdqry1.Connection := mConn;
fdqry1.SQL.Clear;
fdqry1.SQL.Add(SQLStr);
fdqry1.Open();
result := '{result:"OK",DataSet:}';
frmMain.Log.Debug('ok', 'debug');
finally
fdqry1.Free;
mConn.Free;
end;
except
on E: Exception do
begin
result := '{Result:"失败 Error:' + e.message + '"}';
frmMain.Log.Debug('NOok', 'debug');
end;
end;
end;

5、在关闭时候,释放创建的对象

procedure TSrvMethods.DSServerModuleDestroy(Sender: TObject);
begin
oParams.Free;
end;

Delphi XE FireDac 连接池的更多相关文章

  1. Delphi 的 FireDAC 连接管理与配置过程

    Delphi 的 FireDAC 连接管理与配置过程: 使用 FireDAC 技术连接 数据库,主要是使用  TFDConnection ,其中有一参数是选择  ConnectionDefFile. ...

  2. 三句话搞定FireDAC连接池

    form上拖入: FDManager1: TFDManager; FDConnection1: TFDConnection; //初始化连接池procedure TForm1.InitDBPool;b ...

  3. FIREDAC FDConnection 连接池 连接串

    一.FDConnection 连接池 http://docs.embarcadero.com/products/rad_studio/firedac/frames.html?frmname=topic ...

  4. Delphi XE中使用dbExpress连接MySQL数据库疑难问题解决(对三层的例子配置有帮助)

    Delphi IDE中包含一个Data Explorer的组件,如下图所示: 该组件基于dbExpress(包含TSQLConnection.TSQLDataSet.TSQLQuery.TSQLSto ...

  5. Delphi XE中使用dbExpress连接MySQL数据库疑难问题解决

    Delphi IDE中包含一个Data Explorer的组件,如下图所示: 该组件基于dbExpress(包含TSQLConnection.TSQLDataSet.TSQLQuery.TSQLSto ...

  6. Firedac 数据连接池的应用

    procedure TForm2.Button1Click(Sender: TObject); begin if not FDConnection1.Connected then FDConnecti ...

  7. 使用 TFDConnection 的 pooled 连接池

    从开始看到这个属性,就一直认为他可以提供一个连接池管理功能, 苦于文档资料太少, 甚至在帮助中对该属性的使用都没有任何介绍,如果你搜索百度,也会发现基本没资料. 最后终于在其官方网站看到了其完整相关的 ...

  8. DataSnap中连接池的应用

    当开发人员开始创建Delphi的DataSnap应用时很常见的数据库连接定义方式是每个数据模块建立一个连接.这样做将产生大量的数据库连接,并产生很多问题.从Delphi XE开始,EMB提供了Sess ...

  9. Delphi XE 10 跨平台三层数据库应用教程

    Delphi XE 10 跨平台三层数据库应用教程 前言: Delphi XE 开始越来越庞大,比经典的Delphi7难用,但依然是目前所有跨平台开发工具中开发效率最高.最容易上手的,其快速设计RAD ...

随机推荐

  1. 如何在MacOS的VScode上安装Python3

    由于MacOS上的VScode默认安装的Python版本是2.7,所以需要我们自己手动安装Python3从Python官网下载最新版本-安装-设置环境变量当然是可行的,但下面要介绍的是另外一种方式:H ...

  2. 3ds Max File Format (Part 2: The first inner structures; DllDirectory, ClassDirectory3)

    Now that we understand the outer structure of the file, it's time to look closer to what's inside. T ...

  3. Postman:下载安装与基本介绍

    1.下载: (1)官网APP: https://www.getpostman.com/ (即: https://app.getpostman.com/app/download/win64 ) (2)插 ...

  4. Map中放入对象字符串转义问题

    在做Zuul网关日志处理的时候,有以下需求: (1)记录请求成功的日志,要求记录请求返回的结果. 遇到的问题: (1)当请求的结果事对象时,会将其转成字符串,在put进map的时候,字符串就会被转义 ...

  5. Application Comparison Of LED Holiday Light And Traditional Incandescent Lights

    Obviously, LED holiday lights are leading the competition in economical Christmas decorations, but t ...

  6. ajax中的参数

    function login() { $.ajax({ //几个参数需要注意一下 type: "POST",//方法类型 dataType: "json",// ...

  7. Python爬虫之post请求

    暑假放假在家没什么事情做,所以在学习了爬虫,在这个博客园里整理记录一些学习的笔记. 构建表单数据(以http://www.iqianyue.com/mypost 这个简单的网页为例) 查看源代码,发现 ...

  8. jQuery实现TAB选项卡切换特效简单演示

    本文实例为大家分享jQuery实现TAB选项卡切换特效,供大家参考,具体内容如下 1.tab切换 on ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 ...

  9. SQLServer使用链接服务器远程查询

    --创建链接服务器 exec sp_addlinkedserver 'ITSV ', ' ', 'SQLOLEDB ', '远程服务器名或ip地址 ' exec sp_addlinkedsrvlogi ...

  10. Java-POJ1011-sticks

    很经典的搜索题,直接爆搜会卡在连续相同长度的木棍,可以先排序,预处理该长度不行直接跳下一长度木棍的位置 但此题特殊,木棍长度小于50,我们可以直接桶排序 还有就是关于回溯的理解: 我们写的dfs为的是 ...