有关连接对象的更多信息 [英] More on connection object

查看:108
本文介绍了有关连接对象的更多信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我首先想知道..如果不关闭连接会出现什么问题.

这可能是一个简单的问题,但请帮助我

在此先感谢

Ramesh Ch tulal

hello there

I jst want to know that..what will be the problem if we will not close the connection.

it may be simple question but Please help me

Thanks in Advance

Ramesh Ch tulal

推荐答案

当我们打开一个连接时,它将负责在您的应用程序中保留数据库的所有所需操作,但是当我们没有明确关闭连接时会发生什么.它会导致连接泄漏问题如何看待
当我们不关闭/处理连接时,GC会在自己的时间内收集它们,从池的角度来看,此类连接被视为泄漏.我们有一个奇怪的可能性,就是在给定的时间点达到最大池大小值,而实际上并没有全部使用它们,有几个泄漏并且等待GC对其进行处理.即使我们没有使用最大池大小的连接数,这实际上也会导致上述异常.

此类问题的答案是using语句.此声明保证正确清理资源,并以最及时的方式清理它们.

用using语句重新编码后,我们的代码块如下所示:
when we open an Connection it will responsible to hold all desired operation of databases in your application but what happens is when we do not close the connection explicitly. it will lead to Leaking Connection problem how take a look
When we do not close/dispose the connection, GC collects them in its own time, such connections are considered as leaked from pooling point of view. There is a strange possibility that we reach max pool size value and at that given moment of time without actually using all of them, having couple of them leaked and waiting for GC to work upon them. This would actually lead to the exception mentioned above, even if we are not using max pool size number of connections.

The answer to Such type of problems is the using statement. This statement guarantees that resources are properly cleaned up and that they''re cleaned up in the most timely manner.

Recoded with the using statement our code block would look like:
using (SqlConnection connection = new SqlConnection(connectionString))
{
    
}



参考链接:-
ADO.NET连接池一览 [ SqlConnection.Close方法[



Reference Link :-
ADO.NET Connection Pooling at a Glance[^]
SqlConnection.Close Method[^]


这篇关于有关连接对象的更多信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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