我使用与否后关闭与数据库的连接? [英] to close connection to database after i use or not?
问题描述
打开与数据库的连接是否更好-
is it be better to open connection to database -
进行任何查询...更新....删除-
make any querys...update....delete -
,并且在我用来关闭此连接之后
and after i use to close this connection
或
当程序加载-
,并在程序关闭时关闭?
and close when the program close ?
预先感谢
推荐答案
通常,您应在代码中尽快关闭(处置)。使用尝试/最终
或 using
块。
In general, you Close (Dispose) as soon as possible in your code. With a try/finally
or using
block.
实际发生的情况取决于应用程序的ConnectionPool设置。
What actually happens depends on the ConnectionPool settings for your app.
基本上,ConnectionPool的存在意味着您不必担心连接的使用(保持多少连接,保持多长时间),它成为外部配置。
Basically the presence of the ConnectionPool means you don't have to worry about the using of connections (how many, how long to maintain) anymore, it becomes an external configuration.
BTW:除WinCE框架外,略那里有不同的规则。
BTW: With the exception of the WinCE framework, slightly different rules there.
这篇关于我使用与否后关闭与数据库的连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!