System.Data.SqlClient.SqlException 超时时间已到

简介: 错误信息:有关调用实时(JIT)调试而不是此对话框的详细信息,请参见此消息的结尾。************** 异常文本 **************System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: Timeout 时间已到。在操作完成之前超时时间已过或服务器未响应。 (错误详细信息

错误信息:

有关调用实时(JIT)调试而不是此对话框的详细信息,
请参见此消息的结尾。

************** 异常文本 **************
System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: Timeout 时间已到。在操作完成之前超时时间已过或服务器未响应。 (错误详细信息等于 很可能由 IncludeExceptionDetailInFaults=true 创建的 ExceptionDetail,其值为:
System.Data.SqlClient.SqlException: Timeout 时间已到。在操作完成之前超时时间已过或服务器未响应。
在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
在 System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
在 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
在 System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
在 Microsoft.Practices.EnterpriseLibrary.Data.Database.DoExecuteNonQuery(DbCommand command)
在 Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteNonQuery(DbCommand command)



************** 已加载的程序集 **************
mscorlib
程序集版本:4.0.0.0
Win32 版本:4.0.30319.18444 built by: FX451RTMGDR
基本代码:file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------

错误信息或为:

 
System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. (错误详细信息等于 很可能由 IncludeExceptionDetailInFaults=true 创建的 ExceptionDetail,其值为:
System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
   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()
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
   at System.Data.SqlClient.SqlDataReader.get_MetaData()
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunB...)。

Server stack trace: 
   在 System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
   在 System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)


解决方案:

System.Data.Common.DbCommand sqlStringCommand = this.db.GetSqlStringCommand(SQL);
sqlStringCommand.CommandTimeout = 1800000;
this.db.ExecuteNonQuery(sqlStringCommand);

修改Command的TimeOut属性未合适的时间即可。


小注:

         也许你会说,我在连接字符串中已经 设置了 Connect Timeout=80000 ,并且数据库中超时连接也是设置的值是一个很大的值。为啥到了30秒,仍然超时了呢??
         这是因为:
         你的设置并没有问题,是你混淆了  SqlCommand.CommandTimeout  和 SqlConnection.ConnectionTimeout 这两个的区别了。
         你的连接字符串中的超时只是设置的 SqlConnection.ConnectionTimeout 的值,而不是设置的 SqlCommand.CommandTimeout 的值。
         SqlHelper 中并没有 SqlCommand.CommandTimeout 的相关设置。需要你自己设置。
         下面是两个的比较:
         SqlCommand.CommandTimeout
         获取或设置在终止执行命令的尝试并生成错误之前的等待时间。
         等待命令执行的时间(以秒为单位)。默认为 30 秒。
         SqlConnection.ConnectionTimeout
         获取在尝试建立连接时终止尝试并生成错误之前所等待的时间。
         等待连接打开的时间(以秒为单位)。默认值为 15 秒。

小注部分参考:点击打开链接


相关文章
System.InvalidOperationException:“线程间操作无效: 从不是创建控件“xxx”线程它。”
System.InvalidOperationException:“线程间操作无效: 从不是创建控件“xxx”线程它。”
291 0
|
9月前
|
数据库
机房重构问题-System.Data.SqlClient.SqlException:“字符串或二进制数据被截断。
机房重构问题-System.Data.SqlClient.SqlException:“字符串或二进制数据被截断。
39 0
|
网络协议 应用服务中间件
服务器CLOSE_WAIT请求太多的问题
服务器CLOSE_WAIT请求太多的问题
410 0
|
小程序 Java Apache
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
187 0
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
|
XML 网络协议 网络安全
巧用Response.Write(message)中止异常
public void ResponseInfo(string message) { HttpContext.Current.Response.Clear(); HttpContext.
1027 0
|
数据采集 网络协议
一次TIME_WAIT和CLOSE_WAIT故障和解决办法
昨天解决了一个curl调用错误导致的服务器异常,具体过程如下: 里头的分析过程有提到,通过查看服务器网络状态检测到服务器有大量的CLOSE_WAIT的状态。   在服务器的日常维护过程中,会经常用到下面的命令:   它会显示例如下面的信息: TIME_WAIT 814CLOSE_WAIT 1FIN_WAIT1 1ESTABLISHED 634SYN_RECV 2LAST_ACK 1 常用的三个状态是:ESTABLISHED 表示正在通信,TIME_WAIT 表示主动关闭,CLOSE_WAIT 表示被动关闭。
2654 0