[英]ASP.NET Connection time out after being idle for a while
My ASP.NET website while trying to connect to the database for first time after a period of inactivity throws an time out exception. 我的ASP.NET网站在一段时间不活动后尝试首次连接到数据库时,抛出了超时异常。
I understand the connections in the connection pool get terminated after some idle time for some reason (Firewall or Oracle settings) and the pool or app doesn't have a clue about it. 我了解连接池中的连接由于某些原因(防火墙或Oracle设置)而在闲置一段时间后会终止,并且该池或应用程序对此一无所知。
Is there any way to validate the connection beforehand so that the first try doesn't throw an exception? 有没有什么方法可以预先验证连接,以便第一次尝试不会引发异常?
I don't have much control over the DB or Firewall settings. 我对数据库或防火墙设置没有太多控制权。 So I have to deal with this is my application.(would prefer if there is any web.config settings)
因此,我必须处理这是我的应用程序。(如果有任何web.config设置,则首选)
I am using: ASP.NET 2.0. 我正在使用:ASP.NET 2.0。 Oracle server 11g, Microsoft Enterprise Library DAAB to do all my DB operations.
Oracle服务器11g,Microsoft Enterprise Library DAAB可以执行我的所有数据库操作。
I did some search on this topic but didnt find any solid solution for this yet :( 我对此主题进行了一些搜索,但尚未找到任何可靠的解决方案 :(
There is a State property on SqlConnection that you could check 您可以检查SqlConnection上的一个State属性
if(myConnection.State == ConnectionState.Open)
{
// perform your query
}
您可以随时增加连接超时属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.