在多个应用程序之间共享ADOConnectionString-Delphi [英] Sharing ADOConnectionString accross multiple applications-Delphi

查看:160
本文介绍了在多个应用程序之间共享ADOConnectionString-Delphi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Delphi 7,SQL Server 2008 R2,并且正在使用ADO连接到数据库。

I am working on Delphi 7, SQL Server 2008 R2 and i am using ADO to connect to database.

我的连接字符串:

Provider = SQLOLEDB.1;集成安全性= SSPI;持久安全性信息= False;初始目录= TESTDataBase;数据源= TestDataSource

Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TESTDataBase;Data Source=TestDataSource

当我建立TADOconnection.Connected到True Connectin字符串时,将其更改为

when i make my TADOconnection.Connected to True Connectin string is changing it to

Provider = SQLOLEDB.1; Integrated安全性= SSPI;持久性安全性信息= False;初始目录= TESTDataBase;数据源= TestDataSource; 使用准备过程= 1;
自动翻译=正确;数据包大小= 4096;工作站ID = MYMachineName;对数据使用加密=错误;可能时使用列排序规则标记=错误

Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TESTDataBase;Data Source=TestDataSource; Use Procedure for Prepare=1; Auto Translate=True;Packet Size=4096;Workstation ID=MYMachineName;Use Encryption for Data=False;Tag with column collation when possible=False

有10多个应用程序,我计划在所有应用程序中使用相同的连接字符串。
,所以当我连接到FirstApplcation时,我正在创建ADO连接字符串,将其保存在注册表中或某些其他位置,以便我也可以将相同的连接字符串用于其他应用程序。

There are more than 10 applications and i am planning to use the same connection string in all applications. so when i connect to FirstApplcation i am creating ADO Connection string, saving it in registry or some where so i can use the same connection string for other applications also.

同一用户可以运行多个应用程序(可以是2或3或5个应用程序)。

Same user can run more than one application(it can be 2 or 3 or 5 applications).

这里我有3个问题

1)何时需要共享连接?

1)when i need to share connection?

我的意思是创建连接字符串并共享相同的连接字符串(写入注册表或其他位置)

i mean create the connection string and share the same Connection string(write to registry or some where)

创建连接字符串,连接到数据库并共享相同的连接字符串(写到注册表或其他地方)

create the connection string , connect to database and share the same connection string(write to registry or some where)

2)在我的应用程序在获得共享的连接字符串时是否需要再次连接到数据库(TADOConnection.Connected = true)?我想我应该再次连接它,因为它是不同的应用程序:)

2) In my application when i get the shared connection string do i need to connect to database again(TADOConnection.Connected= true)? i think i should connect it again, since it is different application :)

3)对于我的所有应用程序,我都在application(main form)表单show上打开连接,我将在应用程序(主窗体)关闭时关闭连接。因此,只有在应用程序关闭且TADOCOnnection.KeepConnection = True时,连接才会关闭。是在数据库服务器上造成性能问题还是负担?

3) For all my applications i open connection at application(main form) form show and i will be closing connection at application(main form) form close.So connection will get close only when application closes and TADOCOnnection.KeepConnection = True. is this create performance issues or burden on database server?

推荐答案

共享的 UDL 文件可能很适合共享连接。仅对连接字符串使用必需属性,即:


Provider = SQLOLEDB.1; Integrated Security = SSPI;持久安全性
Info = False;初始目录= TESTDataBase;数据源= TestDataSource

Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TESTDataBase;Data Source=TestDataSource

不必担心连接后由ADO 添加的其他属性。这是您使用的特定提供程序的默认属性( SQLOLEDB.1 )。如果使用确切的连接字符串或 UDL 文件(具有公共提供程序),则将在所有其他应用程序中设置相同的属性。
默认情况下,与SQL Server的ADO连接是池化的。

Don't worry about the extra properties that are added by the ADO after you connect. it's the default properties for the specific provider you use (SQLOLEDB.1). The same properties will be set in all your other applications if you use the exact connection string or UDL file (with a common provider). ADO connections to SQL Server are pooled by default.

您可以简单地设置例如

MyConnection.ConnectionString := 'FILE NAME=c:\my_shared_path\shared.udl';
MyConnection.Open;

存放共享连接对象的好地方( TADOConnection )位于整个应用程序的共享数据模块中。
在数据模块或主窗体 OnCreate 事件中打开它。
TADOConnection 被销毁后,连接将自动关闭。

A good place to hold a shared connection object (TADOConnection) is in a shared Data Module for the entire application. Open it in the data module or the main form OnCreate event. The connection is automatically closed once the TADOConnection is destroyed.

这篇关于在多个应用程序之间共享ADOConnectionString-Delphi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆