2009-10-12 102 views
0

我用linq来实现连接到数据库,最近我发现了以下问题,当我打开网站和登录,并且我离开页面闲置大约10分钟时,点击网站中的链接制作一个连接到数据库。 但似乎连接到sql server 2005已经结束,它会自动重新连接到数据库。在这个过程中,它会抛出以下异常:为什么在这种情况下会话到sql服务器?

System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.Data.SqlClient.SqlException: 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.) 

     at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) 
     at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) 
     at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) 
     at System.Data.SqlClient.TdsParserStateObject.WriteSni() 
     at System.Data.SqlClient.TdsParserStateObject.WritePacket(Byte flushMode) 
     at System.Data.SqlClient.TdsParserStateObject.ExecuteFlush() 
     at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc) 
     at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) 
     at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) 
     at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) 
     at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) 
     at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) 
     at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) 
     at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) 
     --- End of inner exception stack trace --- 
     at System.Data.EntityC 

有没有解决这个问题的方法? 每次连接后,linq是否自动关闭连接? 如何设置或配置?

回答

0

几个建议......有什么存储在会话中影响连接?您可以增加会话超时在web.config ...

<system.web> 
    <sessionState timeout="20" /> 
<system.web> 

最后 - 我见过的发生传输级错误......在网络,删除连接错误发生...那里有什么问题?

+0

你有什么建议吗?由于默认设置是timeout =“20”,我是否需要再次配置? – MemoryLeak 2009-10-15 16:02:45

相关问题