获取错误超时已过期。 [英] Getting error timeout expired.

查看:86
本文介绍了获取错误超时已过期。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我们在ASP.NET中开发了一个应用程序,当多个用户一起登录时我们收到了错误



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



所以如何解决这个问题。需要帮助。



我尝试了什么:



我在连接字符串中尝试了最大池限制。,汇集;

Hi,

we have developed a application in ASP.NET when multiple user login together we got error

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

so how to over come this problem .need help.

What I have tried:

I tried max pool limit in connection string .,pooling on;

推荐答案

可能是你正在严重处理SqlConnection对象:如果你在完成它们时没有关闭并处理它们,它们将一直保持打开状态垃圾收集器被激活,因为您的应用程序内存不足或应用程序关闭 - 以先发生者为准。如果你在GC做任何事情之前耗尽连接池,或者你的应用程序关闭,你将收到此错误。

最简单的方法是始终将SqlConnection对象包含在使用 block:
Probably, you are handling SqlConnection objects badly: if you do not close and dispose them when you are finished with them they will remain open until the Garbage Collector gets fired up because your app runs out of memory, or your app closes - whichever happens first. If you exhaust the connection pool before the GC does anything, or your app closes, you will get this error.
The simplest way around this is to always enclose your SqlConnection objects in a using block:
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand cmd = new SqlCommand("SELECT Id, description FROM myTable", con))
        {
        using (SqlDataReader reader = cmd.ExecuteReader())
            {
            while (reader.Read())
                {
                int id = (int) reader["Id"];
                string desc = (string) reader["description"];
                Console.WriteLine("ID: {0}\n    {1}", id, desc);
                }
            }
        }
    }

执行此操作时,当变量超出范围时,连接将自动关闭并处置,所以你的连接不会留给GC。请注意,SqlCommand对象等也是稀缺资源,应该以相同的方式处理。

When you do that, the connection is Closed and Disposed automatically when the variable goes out of scope, so your connections do not get left around for the GC. Note that SqlCommand objects and such like are also scarce resources and should be treated the same way.


这篇关于获取错误超时已过期。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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