We have a .NET program using SQL Server 2008 SP3 Express. Both program and server are on the same machine. It was written with a connection that's opened initially and kept open thereafter. Usually this works OK. But sometimes the program is left idle for hours, during which time the connection is closed and the program bombs on the next SQL access.
我们有一个使用SQL Server 2008 SP3 Express的。net程序。程序和服务器都在同一台机器上。它是用一种最初打开并随后打开的连接写的。通常这是好的。但有时程序会闲置几个小时,在此期间,连接被关闭,并在下一个SQL访问中使用程序炸弹。
The database Auto Close parameter is off. The parameter Pooling=False is in the program connection string. In IIS, for each application pool, recycling has been disabled and idle timeout has been set to 9000 minutes.
数据库自动关闭参数关闭。参数池=False在程序连接字符串中。在IIS中,对于每个应用程序池,回收已被禁用,空闲超时设置为9000分钟。
In testing so far, this works more often than not, but sometimes does not.
在目前的测试中,这种方法通常是可行的,但有时则不然。
1 个解决方案
#1
0
The simplest thing to do would be to check the connection state and open it if necessary:
最简单的做法是检查连接状态并在必要时打开它:
if(conn.State == ConnectionState.Closed)//Can't quite remember the exact syntax
{
conn.Open();
}
//do DB stuff here.
#1
0
The simplest thing to do would be to check the connection state and open it if necessary:
最简单的做法是检查连接状态并在必要时打开它:
if(conn.State == ConnectionState.Closed)//Can't quite remember the exact syntax
{
conn.Open();
}
//do DB stuff here.