如果我不在Asp.Net C#中关闭Sql Conection会发生什么? [英] What Happen If I Do Not Close Sql Conection In Asp.Net C#?

查看:68
本文介绍了如果我不在Asp.Net C#中关闭Sql Conection会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我不在asp.net c#中关闭sql连接会发生什么?但仍然数据交易成功。?diviv =h2_lin>解决方案

取决于。你可能会用完连接,你可能很难创建一个新的DataReader - 它取决于SQL服务器的配置方式,以及代码的工作方式。



当然,如果一个对象实现了IDisposable,你应该总是在完成它时Dispose对象 - 这适用于SqlConnections,SQLCommands等等。



如果是SqlConnection对象,Dispose调用关闭你,所以这是最简单的方法。


如果你打开连接并且不关闭它,那么它会减少连接池和可用于连接的限制再次使用数据库。



建议在使用时明确关闭连接和数据读取器对象。


如果并发用户的数量增加,那么你可能会用完连接。我花了很多时间在旧版本(继承代码)中解决这个问题。



也许这篇文章将帮助您理解问题并提供一些连接处理的最佳实践: ASP.NET - 如何使用(打开/关闭)连接正确 [ ^ ]


what happen if i do not close sql connection in asp.net c#? but still data transaction are working successfully.?

解决方案

Depends. You could run out of connections, you could have difficulty creating a new DataReader - it depends on how the SQL server is configured, and how your code works.

Certainly, if an object implements IDisposable, you should always Dispose the object when you are finished with it - and that applies to SqlConnections, SQLCommands and so forth.

In the case of SqlConnection objects, Dispose calls Close foe you, so it's the easiest way.


If you open the connection and don't close it, then it would decrease the connection pools and limits available for connecting to database again.

It is always recommended to close the connection and data reader objects explicitly when you use them.


If the number of concurrent users increase then perhaps you will run out of connections. I have spent many night fixing this problem in old legacy(inherited code).

Perhaps this article will help you understand the problem and provide some best practices for connection handling: ASP.NET - How To Use(Open/Close) Connections Correctly[^]


这篇关于如果我不在Asp.Net C#中关闭Sql Conection会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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