它是可以接受的,以保持一个数据库连接打开页面的生活吗? [英] Is it acceptable to keep a db connection open for the life of the page?

查看:83
本文介绍了它是可以接受的,以保持一个数据库连接打开页面的生活吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家都知道,你应该关闭你使用完毕后立即连接。

Everybody knows that you should close a connection immediately after you finish using it.

由于我的域对象模型设计的一个缺陷,我不得不离开打开完整的页面生命周期的连接。从本质上讲,我有一个准时财产上打开第一个电话的连接,然后在Page.Unload(..),将检查是否数据库连接是有史以来打开,然后关闭它,如果它是。由于只需要一秒钟,我已经认为它没有太多不是立即关闭它的不同。

Due to a flaw in my domain object model design, I've had to leave the connection open for the full page life cycle. Essentially, I have a Just In Time property which opens a connection on first call, and then on Page.Unload (..) it would check if a db connection was ever open, and then close it if it was. Since it only takes a second, I’ve had the opinion its not too much different than closing it immediately.

这是好吗?还是应该仍然立刻每一个使用后关闭?

Is this ok? Or should it still be closed immediately after every single use?

先谢谢了。

推荐答案

这是不理想,但在它我不会重新写我的应用程序。除非你的网页是做大量的各种方法费时的工作,整个页面生命周期应迅速执行。在实践中它可能只是意味着你的连接对象是开放的几毫秒的时间比它本来否则。这可能是在某些情况下显著,但它听起来并不像它会在你的情况。

It's not ideal but I wouldn't re-write my application over it. Unless your page is doing a large amount of time-consuming work in various methods, the whole page lifecycle should execute quickly. In practice it may just mean that your connection object is open a few milliseconds longer than it would have been otherwise. That might be significant in some scenarios, but it doesn't sound like it would be in your case.

这篇关于它是可以接受的,以保持一个数据库连接打开页面的生活吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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