ASP.NET 连接池问题?

发布于 2024-09-26 11:01:23 字数 189 浏览 0 评论 0原文

我在 ASP.NET 网页中的每个 Insert、Update、Delete 和 Select 方法中创建 SqlConnection 对象。然后我关闭finally 块中的连接对象。但我不确定这是一个好方法。这是连接池的问题吗?

您对如何使用 SqlConnection 和 SqlDataReader 对象有什么建议吗?

谢谢。

I create SqlConnection objects in every Insert,Update,Delete and Select methods in asp.net web pages. Then i close the connection objects in finally block. But im not sure about this is a good way. Is this a problem about connection pool?

Do you have any recommendations about how to use SqlConnection and SqlDataReader objects for me?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼藏柔 2024-10-03 11:01:23

您想要做的就是关闭finally 块中的连接。另一种方法是使用 Using 语句。 using 将适用于任何实现 iDisposable 的对象,包括 sqlconnection,并且将在完成时调用该对象的 dispose,无论是否存在异常。

Closing the connection in the finally block is what you want to do. An alternative would be to use the Using statement. Using will work with any object that implements iDisposable including sqlconnection and will call dispose on the object on completion regardless if there was an exception.

箹锭⒈辈孓 2024-10-03 11:01:23

如果您确实要关闭 SQLConnection,那么我还会检查您的 SQLDataReader 并确保您正在关闭它们。

If you are definitely closing off your SQLConnection then I would also review your SQLDataReader and ensure you are closing those.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文