Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/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
C# ExecuteQueryin linq:超时已过期。操作完成前的超时时间或服务器没有响应_C#_Linq_Sql Server 2008 - Fatal编程技术网

C# ExecuteQueryin linq:超时已过期。操作完成前的超时时间或服务器没有响应

C# ExecuteQueryin linq:超时已过期。操作完成前的超时时间或服务器没有响应,c#,linq,sql-server-2008,C#,Linq,Sql Server 2008,执行datacontext.ExecuteCommandobjectname时出错 错误: System.Data.SqlClient.SqlException:超时已过期。操作完成前已过超时时间,或者服务器没有响应。声明已终止。 示例代码: Datacontext context = new Datacontext(); tablename tb=new tablename(); string DeleteQuery="delete from table A"; context.Execut

执行datacontext.ExecuteCommandobjectname时出错

错误:

System.Data.SqlClient.SqlException:超时已过期。操作完成前已过超时时间,或者服务器没有响应。声明已终止。 示例代码:

Datacontext context = new Datacontext();
tablename tb=new tablename();

string DeleteQuery="delete from table A";
context.ExecuteCommand<tb>(DeleteQuery);
DeleteQuery=string.empty;


string InsertQuery="Insert into table B(a,b,c,d)Select table from C Union All Select Table from D";
context.ExecuteCommand<tb>(InsertQuery);
InsertQuery=string.empty;
在这里,当执行insert查询时,我收到一个错误System.Data.SqlClient.SqlException:超时过期。操作完成前已过超时时间,或者服务器没有响应。声明已终止

错误页面如下所示

“/Portal”应用程序中出现服务器错误。 超时已过期。操作完成前已过超时时间,或者服务器没有响应。 声明已终止。 描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源

异常详细信息:System.Data.SqlClient.SqlException:超时已过期。操作完成前已过超时时间,或者服务器没有响应。 声明已终止

源错误:

第914行:其中ft.IsDeleted=0,ym.IsDeleted=0,ym.IsApproved=1; 第915行: 第916行:dc.ExecuteQueryInsertCommand; 第917行:InsertCommand=string.Empty; 第918行:

源文件:d:\Website\IDCCircle\u Staging\Portal\Default.aspx.cs行:916

堆栈跟踪:

[SqlException 0x80131904:超时已过期。操作完成前已过超时时间,或者服务器没有响应。 该声明已终止。] System.Data.SqlClient.SqlConnection.OnErrorSqlException异常,布尔breakConnection+2062078 System.Data.SqlClient.SqlInternalConnection.OnErrorSqlException异常,布尔断开连接+5050204 System.Data.SqlClient.TdsParser.throweexception和warning+234 System.Data.SqlClient.TdsParser.runBehavior运行行为,SqlCommand cmdHandler,SqlDataReader数据流,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj+2275 System.Data.SqlClient.SqlDataReader.ConsumerMetadata+33 System.Data.SqlClient.SqlDataReader.get_元数据+86 System.Data.SqlClient.SqlCommand.FinishExecuteReaderSqlDataReader ds,RunBehavior RunBehavior,字符串重置选项String+311 System.Data.SqlClient.SqlCommand.RunExecuteReaderTdsCommandBehavior cmdBehavior,RunBehavior RunBehavior,布尔返回流,布尔异步+987 System.Data.SqlClient.SqlCommand.RunExecuteReaderCommandBehavior cmdBehavior、RunBehavior RunBehavior、布尔返回流、字符串方法、DbAsyncResult+162 System.Data.SqlClient.SqlCommand.RunExecuteReaderCommandBehavior cmdBehavior,RunBehavior RunBehavior,布尔返回流,字符串方法+32 System.Data.SqlClient.SqlCommand.ExecuteReaderCommandBehavior,字符串方法+141 System.Data.SqlClient.SqlCommand.ExecuteDbDataReaderCommandBehavior+12 System.Data.Common.DbCommand.ExecuteReader+12 System.Data.Linq.SqlClient.SqlProvider.ExecuteExpression查询,查询信息查询信息,IOObjectReaderFactory工厂,对象[]父参数,对象[]用户参数,ICompiledSubQuery[]子查询,对象lastResult+1266 System.Data.Linq.SqlClient.SqlProvider.ExecuteAlExpression查询,查询信息[]查询信息,IOObjectReaderFactory工厂,对象[]用户参数,ICompiledSubQuery[]子查询+113 System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.ExecuteExpression query+344 System.Data.Linq.DataContext.ExecuteMethodCallObject实例,MethodInfo MethodInfo,Object[]参数+83 System.Data.Linq.DataContext.ExecuteQueryString查询,对象[]参数+265 _d:\Website\IDCCircle\u Staging\Portal\Default.aspx.cs:916中的Default.NHPgridbind _Default.Page\u LoadObject sender,d:\Website\IDCCircle\u Staging\Portal\Default.aspx.cs:97中的事件参数e System.Web.Util.CalliHelper.EventArgFunctionCallerIntPtr fp、对象o、对象t、事件参数e+14 System.Web.Util.CallEventHandlerDelegateProxy.CallbackObject发送方,EventArgs e+35 System.Web.UI.Control.OnLoadEventArgs e+91 System.Web.UI.Control.LoadRecursive+74 System.Web.UI.Page.ProcessRequestMain布尔IncludeStages在区域同步点之前,布尔IncludeStages在区域同步点+2207


版本信息:Microsoft.NET Framework版本:4.0.30319;ASP.NET版本:4.0.30319.272

如果表C和D包含大量行,则运行insert所需的时间可能比默认命令超时30秒更长。在insert命令之前添加此行:

context.CommandTimeout = 240  // set timeout to 4 minutes
顺便说一下,您应该在处理完上下文后再处理它。最简单的方法是:

using (Datacontext context = new Datacontext())
{
    // your code goes here
}