为什么在这种情况下sql server的会话出来了?

时间:2009-10-12 15:21:25

标签: c# asp.net linq-to-entities

我使用linq来连接到数据库,最近我发现了以下问题,当我打开网站并登录时,我让页面空闲了大约10分钟,点击网站上的链接与数据库的连接。 但似乎连接到sql server 2005已经出来了,它会自动重新连接到数据库。在此过程中,它会抛出以下异常:

 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是否会自动关闭连接? 如何设置或配置?

1 个答案:

答案 0 :(得分:0)

一些建议......会话中是否存储了影响连接的内容?您可以在web.config中增加会话超时...

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

最后 - 我已经看到发生了传输级错误... 错误发生在丢弃连接的网络上......那里有任何问题吗?