使用最大池大小时发生错误 [英] Error occurred while working with max pool size

查看:64
本文介绍了使用最大池大小时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在使用ADO.Net C#连接SQL数据库时,我在使用时会随机获得异常同时在线程中执行数千个数据,例如

In connectivity of SQL database using ADO.Net C#, I am getting exceptions randomly while working with thousands of data simultaneously which is being executed in thread such as




  • 与服务器成功建立连接,但在登录前握手期间发生错误。(提供者:SSL提供者,错误:0 - 等待操作超时。)

  • A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 0 - The wait operation timed out.)


由于登录前连接初始化过程中的错误,客户端无法建立连接。可能的原因包括:客户端尝试连接到不受支持的SQL Server版本;服务器是忙于
接受新连接;或者服务器上存在资源限制(内存不足或允许的最大连接数)。(提供者:TCP提供者,错误:0 - 远程主机强制关闭现有连接。 )

The client was unable to establish a connection because of an error during connection initialization process before login. Possible causes include the following: the client tried to connect to an unsupported version of SQL Server; the server was too busy to accept new connections; or there was a resource limitation (insufficient memory or maximum allowed connections) on the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)

>
Timeout expired。在从池中获取连接之前已经过了超时时间。这可能是因为所有池连接都在使用中并且达到了最大池大小。

Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.


我的连接字符串为

My connection string is as

<add name="ConnDBString" connectionString="datasource;Initial Catalog=dbname;pooling=true;connection lifetime=120;Max Pool Size=1000" providerName="System.Data.SqlClient"/>  



在参考其他问题时,我优化了我的连接建立代码,如下所示

In reference of other questions I have optimized my code for connection establishment like below

public static int ExecuteNonQuery(string commandText, CommandType commandType, ref List<SqlParameter> parameters)
    {
        int result = 0;
        if (!string.IsNullOrEmpty(commandText))
        {
            using (var cnn = new SqlConnection(Settings.GetConnectionString()))
            {                    
                var cmd = cnn.CreateCommand();
                cmd.CommandText = commandText;
                cmd.CommandType = commandType;
                cmd.CommandTimeout = Convert.ToInt32(Settings.GetAppSetting("CommandTimeout") ?? "3600");
                cmd.Parameters.AddRange(parameters.ToArray());
                cnn.Open();
                result = cmd.ExecuteNonQuery();
                cmd.Dispose();                    
            }
        }
        return result;
    }



请指教。

Please advise.


推荐答案

Hi PinkiPatra,

Hi PinkiPatra,




根据您的错误消息,我建议您查看一下这篇文章,它解释了导致此错误的可能原因:

According to your error message, I would suggest that you could take a look at this article which explains possible causes for this error:

http://blogs.msdn.com/ b /穗/存档/ 2009/04/16 / A时,送的请求到所述服务器提供商-TCP-提供商传输 - 电平 - 误差已-发生-误差-0-AN-现有连接被强制关闭 - 远程主机.aspx



这篇文章解释了安装"需要"的问题; .NET Framework 4的可靠性更新1":

http://blogs.msdn.com/b/spike/archive/2009/04/16/a-transport-level-error-has-occurred-when-sending-the-request-to-the-server-provider-tcp-provider-error-0-an-existing-connection-was-forcibly-closed-by-the-remote-host.aspx

And this article, which explains the need for installing "Reliability Update 1 for the .NET Framework 4":

http://blogs.msdn.com/b/adonet/archive/2011/11/05/minimizing-connection-pool-errors-in-sql-azure.aspx



Microsoft .NET Framework 4可靠性更新1(KB2533523)的下载页面

http://blogs.msdn.com/b/adonet/archive/2011/11/05/minimizing-connection-pool-errors-in-sql-azure.aspx

Download page for Microsoft .NET Framework 4 Reliability Update 1 (KB2533523)

http://www.microsoft.com/en-us/download/details.aspx?id=27014

此外,如果问题仍然存在,请您分享更多信息,例如相关的开发环境,以及如何重现问题的步骤。

In addition, if the issue still exists, could you please share a bit more information, such as related developing environment, the steps about how to reproduce the issue on my side.

祝你好运,

张龙


这篇关于使用最大池大小时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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