当前位置: 首页 > 编程日记 > 正文

使用 TFDConnection 的 pooled 连接池

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

最后终于在其官方网站看到了其完整相关的英文资料,虽然没有正面介绍该属性,但却是要启用该属性的详细方法:

Defining Connection (FireDAC)

General

connection definition is a set of parameters that defines how to connect an application to a DBMS using a specific FireDAC driver. It is the equivalent of a BDE alias, ADO UDL (stored OLEDB connection string), or ODBC Data Source Name (DSN). For the list of supported database management systems and corresponding parameters, see FireDAC Database Connectivity.

FireDAC supports 3 connection definition kinds:

TypeDescriptionProsCons
PersistentHas a unique name, is managed by the FDManager, and is stored in a connection definition file.May be defined once and reused across many applications. May be pooled.The parameters (server address, DB name, and so on) are publicly visible and may be changed incidentally.

FDManager has to be reactivated or the Delphi IDE has to be restarted to make a newly added definition visible at design time.

PrivateHas a unique name, is managed by the FDManager, but is NOT stored in a connection definition file.Connection definition parameters are not visible "outside" the application. May be pooled.The application needs to create a private connection definition after each program restarts and cannot share it with the other programs.

Cannot be created at design time.

TemporaryHas no name, is not stored in a connection definition file, and is not managed by the FDManager.The simplest way to create a connection definition is to fill in the TFDConnection.Params property.

Can be created at design time using the TFDConnection component editor.

Similar to private. Also cannot be referenced by name and cannot be pooled.

Connection Definition File

The persistent connection definitions are stored in an external file - the connection definition file. This file has the standard INI text file format. It can be edited by FDExplorer or FDAdministrator utilities at first, manually, or by code. By default the file is C:\Users\Public\Documents\Embarcadero\Studio\14.0\FireDAC\FDConnectionDefs.ini.

Note: If you add a new persistent connection definition using FDExplorer or FDAdministrator while the RAD Studio IDE is running, it is not visible to the FireDAC design time code. To refresh the persistent connection definitions list, you need to reactivate FDManager or restart the RAD Studio IDE.

Sample content of this file:

[Oracle_Demo]
DriverID=Ora Database=ORA_920_APP User_Name=ADDemo Password=a MetaDefSchema=ADDemo ;MonitorBy=Remote   [MSSQL_Demo] DriverID=MSSQL Server=127.0.0.1 Database=Northwind User_Name=sa Password= MetaDefSchema=dbo MetaDefCatalog=Northwind MonitorBy=Remote

An application can specify a connection definition file name in the FDManager.ConnectionDefFileName property. FireDAC searches for a connection definition file in the following places:

  • If ConnectionDefFileName is specified:
    • search for a file name without a path, then look for it in an application EXE folder.
    • otherwise just use a specified file name.
  • If ConnectionDefFileName is not specified:
    • Look for FDConnectionDefs.ini in an application EXE folder.
    • If the file above is not found, look for a file specified in the registry key HKCU\Software\Embarcadero\FireDAC\ConnectionDefFile. By default it is C:\Users\Public\Documents\Embarcadero\Studio\14.0\FireDAC\FDConnectionDefs.ini.
Note: At design time, FireDAC ignores the value of the FDManager.ConnectionDefFileName, and looks for a file in a RAD Studio Bin folder or as specified in the registry. If the file is not found, an exception is raised.

If FDManager.ConnectionDefFileAutoLoad is True, a connection definition file loads automatically. Otherwise, it must be loaded explicitly by calling the FDManager.LoadConnectionDefFile method before the first usage of the connection definitions. For example, before setting TFDConnection.Connected to True.

Creating a Persistent Connection Definition

A persistent connection definition can be created using FDExplorer or FDAdministrator. Here is how you can do that in code. Also see the demo FireDAC\Samples\Comp Layer\TFDConnection\ConnectionDefs.

The following code snippet creates a connection definition named "MSSQL_Connection", which has all parameters required to connect to the Microsoft SQL Server running locally, using the OS authentication (SSPI):

usesFireDAC.Comp.Client, FireDAC.Stan.Intf; var oDef: IFDStanConnectionDef; begin oDef := FDManager.ConnectionDefs.AddConnectionDef; oDef.Name := 'MSSQL_Connection'; oDef.DriverID := 'MSSQL'; oDef.Server := '127.0.0.1'; oDef.Database := 'Northwind'; oDef.OSAuthent := True; oDef.MarkPersistent; oDef.Apply; ..................... FDConnection1.ConnectionDefName := 'MSSQL_Connection'; FDConnection1.Connected := True;

FDManager is a global instance of the FireDAC connection manager. Its property FDManager.ConnectionDefs: IFDStanConnectionDefs is a collection of the persistent and private connection definitions. The AddConnectionDef method adds a new connection definition. The MarkPersistent method marks a connection definition as persistent. The Apply method saves a connection definition to a connection definition file. Without the MarkPersistent call, the connection definition is private.

Creating a Private Connection Definition

A private connection definition can be created only in code. The code is similar to the one above, but without the MarkPersistent call.

Also, you can use a technique similar to BDE:

varoParams: TStrings;
beginoParams := TStringList.Create; oParams.Add('Server=127.0.0.1'); oParams.Add('Database=Northwind'); oParams.Add('OSAuthent=Yes'); FDManager.AddConnectionDef('MSSQL_Connection', 'MSSQL', oParams); ..................... FDConnection1.ConnectionDefName := 'MSSQL_Connection'; FDConnection1.Connected := True;

Creating a Temporary Connection Definition

A temporary connection definition can be created at design time using the FireDAC Connection Editor. In order to do this, double-click a TFDConnection to invoke the editor:

Defining.png

Or at run time in code by filling the TFDConnection.Params property. This is the simplest way to create a connection definition.

FDConnection1.DriverName := 'MSSQL'; FDConnection1.Params.Add('Server=127.0.0.1'); FDConnection1.Params.Add('Database=Northwind'); FDConnection1.Params.Add('User_name=sa'); FDConnection1.Connected := True;

Another option is to specify a connection string at run time by filling the TFDConnection.ConnectionString property. A connection string may be a convenient way to specify connection definition parameters for certain types of applications. For example:

FDConnection1.ConnectionString := 'DriverID=MSSQL;Server=127.0.0.1;Database=Northwind;User_name=sa'; FDConnection1.Connected := True;

Editing a Connection Definition

An application may need an ability to create and edit a connection definition at run time using standard FireDAC Connection Editor dialog. To edit a temporary connection definition stored in TFDConnection, use the code:

usesFireDAC.VCLUI.ConnEdit; ... if TfrmFDGUIxFormsConnEdit.Execute(FDConnection1, '') then FDConnection1.Connected := True;

To edit a connection definition represented as a FireDAC connection string, use the code:

usesFireDAC.VCLUI.ConnEdit; ... var sConnStr: String; ... sConnStr := FDConnection1.ResultConnectionDef.BuildString(); if TfrmFDGUIxFormsConnEdit.Execute(sConnStr, '') then begin FDConnection1.ResultConnectionDef.ParseString(sConnStr); FDConnection1.Connected := True; end;

转载于:https://www.cnblogs.com/zhenfei/p/4105515.html

相关文章:

Java与UML交互图

Java与UML交互图 前面我们主要讨论的是UML类图,下面我们要讨论的是另一种UML图——交互图(Interaction Diagram)。交互图描述的是一组对象之间的交互过程,或者说,这里我们实际上要回答这样一个问题:“方法调…

1054 The Dominant Color

1. 此题用到了map<string,int>将输入的颜色(long long也存不下&#xff0c;只好作为string存入)的次数记录&#xff0c;看来默认一个没出现过的string对应的int是0。因此记次数的时候 if(mp[str])mp[str] 1;//如果不是第一次出现&#xff0c;出现次数1 else mp[str] …

通过sqlserver日志恢复误删除的数据

通过sqlserver日志恢复误删除的数据 原文:通过sqlserver日志恢复误删除的数据如果你已经急的焦头烂额&#xff0c;看到这篇文章的时候&#xff0c;请你换个坐姿&#xff0c;深呼吸几次&#xff0c;静下心来将这篇文章读完&#xff0c;也许你的问题迎刃而解。 我遇到的情况是这样…

关于在phpStudy环境下,windows cmd中 php不是内部命令问题

首先查看system32是否加入系统变量 其次要把当前运行的php版本的路径加入到系统变量中去&#xff0c;path中&#xff0c; 一定要是这个样子的&#xff1b; D:\phpStudy\php\php-5.6.27-nts 不然没有什么用。 这样在phpstorm中以及cmd中都可以使用php命令了。

如何用javascript控制上传文件的大小

以下是引用片段&#xff1a;<form nameMyform οnsubmit"return CheckFileSize()"> <input typefile namephoto><br/> <input typesubmit valuesubmit></form> <SCRIPT LANGUAGE"JavaScri…

1071 Speech Patterns 需再做

1. alphanumerical 的意思是字母数字混合编制的&#xff0c;也就是一句话中被认为是“单词”的组成成分的有数字和字母。这也是为什么例句中can1不被认为是can。 由于这道题对大小写不敏感&#xff0c;不妨在读入后&#xff0c;把大写字母全部改成小写 //大写换小写 for(int…

IOS类似9.png

图形用户界面中的图形有两种实现方式&#xff0c;一种是用代码画出来&#xff0c;比如Quartz 2D技术&#xff0c;狠一点有OpenGL ES&#xff0c;另一种则是使用图片。 代码画的方式比较耗费程序员脑力,CPU或GPU; 图片则耗费磁盘空间,会增加app的体积.一般的app我们会偏重于使用…

Shell 编程

Shell 是一个用 C 语言编写的程序&#xff0c;通过 Shell 用户可以访问操作系统内核服务。它类似于 DOS 下的 command 和后来的 cmd.exe。Shell 既是一种命令语言&#xff0c;又是一种程序设计语言。Shell script 是一种为 shell 编写的脚本程序。Shell 编程一般指 shell 脚本编…

表现层框架Struts/Tapestry/JSF架构比较 [转]

http://www.jdon.com/artichect/sjt.htm Struts/Tapestry/JSF是目前J2EE表现层新老组合的框架技术。从诞生时间上看&#xff0c;Struts应该比较早&#xff0c;使用得非常广泛&#xff0c;Tapestry 3.0逐渐引起广泛的重视&#xff0c;正当Tapestry即将大显身手时期&#xff0c;S…

1022 Digital Library

1. 关键数据结构 map<string,vector<string> > mp[6] 其中mp[1]代表从书名映射到id&#xff08;id可能无&#xff0c;可能不止一个&#xff0c;所以要用vector&#xff09;&#xff0c;mp[2]是从作者映射到id……mp[5]代表从year映射到id。 2. 卡住的第一个地方是…

event.keyCode用法及列表

用户名&#xff1a;<input type"text" id"UserAccount" onKeyPress"JumpByEnter(UserPwd)" />密码&#xff1a;<input name"UserPwd" type"password" onKeyPress"IsEnterKeyPress()"> JavaScript&…

网络游戏术语(转)

转自&#xff1a;https://site.douban.com/149989/widget/notes/8053161/note/231207595/ AC – Armor Class&#xff0c;盔甲等级、级别Account – 账号&#xff0c;与密码Password相对Add – 一只玩家加入到组队中&#xff0c;如果请求别人组队&#xff0c;可说Add me pls.AO…

vim的一些快捷键,备忘

vim的一些快捷键&#xff0c;备忘 快捷键 作用ctrlg 显示当前行的信息G 跳到某一行:%s/oldtxt/newtxt/g …

1051 Pop Sequence(两种双指针思路)

目录 思路一&#xff1a;以入栈序列为总纲&#xff0c;2层循环&#xff0c;外for内while 思路二&#xff1a;一层while 思路一&#xff1a;以入栈序列为总纲&#xff0c;2层循环&#xff0c;外for内while 注意弹栈之前要判空&#xff0c;不然会出现段错误。 AC代码 #inclu…

iOS底层原理 - 常驻线程

iOS底层原理 - 常驻线程 在 AFN 2.0 时代&#xff0c;会经常看到 AFN 创建一个常驻线程的方式&#xff1a; 0️⃣ AFN 2.0 时代的常驻线程 (NSThread *)networkRequestThread {static NSThread *_networkRequestThread nil;static dispatch_once_t oncePredicate;dispatch_on…

A monad tutorial for Clojure programmers (part 3)

Before moving on to the more advanced aspects of monads, let’s recapitulate what defines a monad (see part 1 and part 2 for explanations): A data structure that represents the result of a computation, or the computation itself. We haven’t seen an example…

Flex精华摘要--使用AS脚本

在MXML文件中实现ActionScript逻辑的几种方法&#xff1a;最简单的方法&#xff0c;在一个MXML文件中通过组件的事件直接书写简单的逻辑控制&#xff0c;但是并不推荐。 <?xml version"1.0" encoding"utf-8"?> <mx:Application xmlns:mx"h…

(C++)自定义链表并写入

确定链表节点的组成&#xff0c;一般由数据和指针构成 struct node{int data;//数据域node* next;//指针域 }; 使用new运算符为节点分配内存空间 node* p new node; 编写创建列表函数&#xff0c;参数为链表的长度(从用户输入读入)&#xff0c;返回值为创建的列表的头指针…

Unicode转义(\uXXXX)的编码和解码

在涉及Web前端开发时, 有时会遇到\uXXXX格式表示的字符, 其中XXXX是16进制数字的字符串表示形式, 在js中这个叫Unicode转义字符, 和\n \r同属于转义字符. 在其他语言中也有类似的, 可能还有其它变形的格式. 多数时候遇到需要解码的情况多点, 所以会先介绍解码decode, 后介绍…

BZOJ 2004 [Hnoi2010]Bus 公交线路

题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id2004 题解 状压dp&#xff0c;记f[i][S]f[i][S]f[i][S]表示[1,i−p][1,i-p][1,i−p]的车都被安排好了&#xff0c;而[i−p1,i][i-p1,i][i−p1,i]的车中&#xff0c;SSS中有111的位置都安排有车停&#xff0c;并且恰…

【转载】C语言编译全过程

今天在blog.chinaunix.net/u3博客看到一篇关于语言编译过程的文章&#xff0c;觉得精简&#xff0c;清晰所以摘录下来我的blog。作为一个程序员了解编译过程对程序的编写也很有帮助。下面是博文的内容&#xff1a;编译的概念&#xff1a;编译程序读取源程序&#xff08;字符流&…

5层模型中数据从源主机到目的主机之旅

报文是用户发送的数据 传输层可能对报文进行拆分&#xff0c;加上段头 网络层会加上网络层的头&#xff0c;构成的协议数据单元叫做数据报 链路层会加头加尾构造帧 路由器的链路层会去掉帧头帧尾&#xff0c;还原到网络层数据报 再次封装成链路层的数据帧 目的主机的链路层再…

JavaScript模式读书笔记 第5章 对象创建模式

1&#xff0c;命名空间模式 namespace <script>var myApp {};//通过全局变量来实现命名空间maApp.Parent function (){};myApp.Child function(){};</script>通用命名空间函数<script>//不安全代码var myApp {};//安全代码if(typeof myApp "undef…

174. Dungeon Game

一、题目 1、审题 2、分析 只能向右、向下移动的王子&#xff0c;从左上角要到右下角救公主&#xff0c;每经过一个方格&#xff0c;可能获得血瓶加血量&#xff0c;或者碰到怪物减血量&#xff0c;当王子血量 < 1 时就挂了&#xff0c;为了能成功救得公主&#xff0c;求王子…

DotNetNuke安装与下载

【下载专区】 DotNetNuke (DNN) 5.1 稳定版正式发布 http://www.dnnmix.com/dotnetnuke-dnn-51-released/ DotNetNuke (DNN) 资源共享 http://www.dnnmix.com/resources/ DotNetNuke官方下载 http://www.dotnetnuke.com/tabid/125/default.aspx 【安装教程】 DotNetNuke安装大…

1025 反转链表

1. 第一次做链表题&#xff0c;但是这题其实也就是套了个链表的壳子&#xff0c;虽然在结点的结构体里面有下一节点地址next这个属性&#xff0c;但是也只在最初给结点标序号时用到&#xff0c;由于没有真正对链表实施倒序&#xff0c;所以后面输出的下一结点的地址实际上只是算…

关于margin

<html><body><div style"width:200px;height:200px;background-color:red;> <div style"width:100px;height:100px;background-color:black;margin-left:300px;"></div></div></body></html> 左边是火狐显示&a…

DNS迭代式和递归式域名查询对比

背景知识&#xff1a;DNS数据库是树状的层次式的 本地域名服务器并不在这个体系当中&#xff0c;它相当于这个体系面向用户的代理。 迭代式&#xff1a;DNS server告诉用户&#xff1a;我不认识这域名&#xff0c;但我知道你可以问哪个DNS服务器 递归式&#xff1a;用户告诉D…

UIActionSheet在iOS8中被弃用造成的错误

UIActionSheet在iOS7.0中效果图如下&#xff1a; UIActionSheet在iOS8中效果图如下&#xff1a; 造成这样的原因&#xff0c;是因为此控件在iOS8中被弃用了&#xff0c;而使用了UIAlertViewController替代的原因&#xff0c;具…

SQL分页语句(转)

有关分页 SQL 的资料很多&#xff0c;有的使用存储过程&#xff0c;有的使用游标。本人不喜欢使用游标&#xff0c;我觉得它耗资、效率低&#xff1b;使用存储过程是个不错的选择&#xff0c;因为存储过程是经过预编译的&#xff0c;执行效率高&#xff0c;也更灵活。先看看单条…