最佳实践ms sql server连接在大型C#或vb.net应用程序中 [英] Best practice ms sql server connection in large C# or vb.net application

查看:91
本文介绍了最佳实践ms sql server连接在大型C#或vb.net应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个大型应用程序中,几个模块需要连接ms sql server。



1)在开始时打开一个连接并进行所有数据检索并仅在应用程序终止时关闭数据连接。



0r



2)每次数据检索都需要连接数据库并在检索后关闭连接。



我想知道哪一个是大型数据库软件开发的最佳方法。



谢谢

in a large application where several module need to connect ms sql server.

1) open a connection at very beginning and do all the data retrieval and close the data connection only when application terminate.

0r

2) every data retrieval need to connect database and after retrieval close the connection.

I like to know which one is the best approach in large database software development.

thanks

推荐答案

选项#2。总是选项#2。



在应用程序的生命周期内保持连接打开永远不是一个好主意。
Option #2. Always option #2.

It's NEVER a good idea to leave a connection open for the lifetime of an application.


随便可能是建筑物,处理物品,当不再需要时将是最好的做法。



好处

- >它有助于缩短您的执行时间。

- >当您处理对象时,它可以将该连接提供给其他应用程序。



注意

As您可能知道DataBases的连接数量有限。

因此,如果您在没有任何需要的情况下长时间打开和处置,那么这只会增加数量。

经过一定数量的连接,即使你创建连接,DataBase也不会连接。
Whatever may be the architecture, disposing objects, when it is no longer required will be the best practice.

Benefits
-> It helps to improve your Execution Time.
-> As you are disposing the object, so it can give that connection to other application.

Note
As you might know the DataBases have limited number of connections.
So, if you will open and dispose after a long time without any need, then that will just increase the number.
After a certain number of connections, DataBase will not connect even if you create connections.


最好在数据检索完成时关闭连接。



=>数据库的连接数有限,如果你关闭它,就会给别人提供连接。

=>如果连接处于打开状态,你试图在你的应用程序中再次打开它

它会抛出一个错误

=>如果你没有在每次打开时关闭连接,只需将

数据库代码包装在一边使用,它将自动关闭连接

当范围丢失时。

=>这是一个很好的做法,尽可能晚地打开连接并尽早关闭
It is best practice to close the connection when ever data retrieval has completed.

=>data base has limited connections it gives the connections to others if u close that.
=>if the connection is in open state and you are try to open it again in your application
it throws an error
=> and if you are not intreasting in closing the connection every time you open,just wrap the
data base code in side using,it will take care of closing the connection automatically
when scope is lost.
=>its a good practice to open the connection as late as possible and close it as early as possible


这篇关于最佳实践ms sql server连接在大型C#或vb.net应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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