Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net Windows服务SQL超时异常_Asp.net_.net_Sql Server 2008_Windows Services - Fatal编程技术网

Asp.net Windows服务SQL超时异常

Asp.net Windows服务SQL超时异常,asp.net,.net,sql-server-2008,windows-services,Asp.net,.net,Sql Server 2008,Windows Services,我有一个Windows服务,每10秒连续查询一次SQL Server数据库表,我还有一个网站,25秒后也会查询同一个数据库表 一段时间后,我收到异常-服务器超时异常已发生。我浏览了堆栈溢出站点,并对SQL配置设置进行了更改,但仍然得到了相同的异常。怎么办 堆栈跟踪 位于System.Data.SqlClient.SqlConnection.OnError(SqlException 异常,布尔断开连接)位于 System.Data.SqlClient.SqlInternalConnection.O

我有一个Windows服务,每10秒连续查询一次SQL Server数据库表,我还有一个网站,25秒后也会查询同一个数据库表

一段时间后,我收到异常-
服务器超时异常已发生
。我浏览了堆栈溢出站点,并对SQL配置设置进行了更改,但仍然得到了相同的异常。怎么办

堆栈跟踪

位于System.Data.SqlClient.SqlConnection.OnError(SqlException 异常,布尔断开连接)位于 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException 异常,布尔断开连接)位于 System.Data.SqlClient.TdsParser.throweexception和warning()位于 System.Data.SqlClient.TdsParser.Run(RunBehavior, SqlCommand cmdHandler、SqlDataReader数据流、, BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)位于System.Data.SqlClient.SqlDataReader.ConsumerMetadata()处 位于System.Data.SqlClient.SqlDataReader.get_MetaData()处 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, 运行行为运行行为,字符串重置选项字符串)位于 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior、RunBehavior、Boolean returnStream、Boolean 异步)在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior、布尔返回流、字符串 方法,DbAsyncResult(结果)位于 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior、布尔返回流、字符串 方法)在 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior 行为,字符串方法)在 System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior 行为)在 System.Data.Common.DbCommand.ExecuteReader(命令行为)
在 Microsoft.Practices.EnterpriseLibrary.Data.Database.DoExecuteReader(DbCommand 命令,命令行为(cmdBehavior)位于 Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteReader(DbCommand 命令)在 Microsoft.Practices.EnterpriseLibrary.Data.CommandAccessor
1.d_u0.MoveNext()
位于System.Collections.Generic.List
1..ctor(IEnumerable
1 collection)
at System.Linq.Enumerable.ToList[t源](IEnumerable
1源) 位于的System.Runtime.Remoting.Messaging.Message.Dispatch(对象目标,布尔fExecuteInContext) System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg,Int32 methodPtr,布尔值fExecuteInContext)


给我看代码!超时异常通常是因为您没有关闭数据库连接

尝试在算法的最后添加代码

if (connection.State == System.Data.ConnectionState.Open)
    {
        connection.Close();
        connection.Dispose();
    }
如果您使用EnterpriseLibrary,请尝试为commandTimeOut添加更多时间

DbCommand dbcommand = database.GetStoredProcCommand("usp_TheStoredProcedureName");
dbcommand.CommandTimeout = 120;

首先向我们显示完整的堆栈跟踪和异常消息。您需要确定发生这种情况的位置。是否是连接、事务、命令等。使用一些日志来确定错误所在的位置并发布异常跟踪。这会给你一些需要调整的线索。就目前而言,您的问题就像读心术一样。我使用企业库和DatabaseFactory.CreateDatabase()方法获取数据库并对其执行存储过程。所以需要关闭连接吗?超时已过期。操作完成前已过超时时间,或者服务器没有响应。该语句已终止。@RaviKhapate:请不要将代码示例或示例数据放入注释中-因为您无法格式化它,所以很难读取它。。。。取而代之的是:通过编辑你的问题来更新它,以提供额外的信息!非常感谢。