且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

围绕一个SqlConnection传递

更新时间:2023-01-08 12:41:31

如果你打算做了很多电话的一排,而且很容易传递一个打开的连接,那么,重用打开的连接。

If you're going to make a lot of calls in a row, and it's easy to pass in an open connection, then yes, reuse the open connection.

这是不是非常重要的,但。因为它使用的是没有那么多。 ADO.NET管理是否为你的好工作。请参见连接池。如果你的code会变得复杂和怪异的方便一个单一的,开放的连接对象,这是不值得的。

This is not incredibly important though. Not as much as it used to be. ADO.NET does a good job of managing this for you. See Connection Pooling. If your code is going to get complicated and weird to facilitate one single, open connection object, it's not worth it.

(现在,确保你的连接对象(无论是否重用与否)的的处理的,当然是非常重要的,因为我敢打赌,你已经知道了。)

(Now, making sure your connection objects (whether reused or not) are disposed of is of course really important, as I bet you already know.)