我有个问题:如何在asp.net MVC页面中处理操作超时。加载正在查询数据库SQL Server的页面时,会加载产品。有时它说等待操作超时。如何处理它。等待操作超时mvc
回答
为了避免在运行非常长的查询时发生等待操作超时异常,请更改SQL命令属性并允许该命令在调用超时之前等待较长时间。
using System;
using System.Data.SqlClient;
///
public class A {
///
public static void Main() {
string connectionString = "";
// Wait for 5 second delay in the command
string queryString = "waitfor delay '00:00:05'";
using (SqlConnection connection = new SqlConnection(connectionString)) {
connection.Open();
SqlCommand command = new SqlCommand(queryString, connection);
// Setting command timeout to 1 second
command.CommandTimeout = 1;
try {
command.ExecuteNonQuery();
}
catch (SqlException e) {
Console.WriteLine("Got expected SqlException due to command timeout ");
Console.WriteLine(e);
}
}
}
}
的LINQ的执行到SQL查询可能需要更长的时间&超过DataContext类的CommandTimeout属性的默认值。 默认值是30秒。 我们可以在每次创建LINQ to SQL DataContext对象并调用查询之前设置CommandTimeout的值。
#region Constructors
/// <summary>
/// Initializes a new FrameworkEntities object using the connection string found in the 'FrameworkEntities' section of the application configuration file.
/// </summary>
public FrameworkEntities() : base("name=FrameworkEntities", "FrameworkEntities")
{
this.ContextOptions.LazyLoadingEnabled = true;
this.CommandTimeout = 300;
OnContextCreated();
}
/// <summary>
/// Initialize a new FrameworkEntities object.
/// </summary>
public FrameworkEntities(string connectionString) : base(connectionString, "FrameworkEntities")
{
this.ContextOptions.LazyLoadingEnabled = true;
this.CommandTimeout = 300;
OnContextCreated();
}
/// <summary>
/// Initialize a new FrameworkEntities object.
/// </summary>
public FrameworkEntities(EntityConnection connection) : base(connection, "FrameworkEntities")
{
this.ContextOptions.LazyLoadingEnabled = true;
this.CommandTimeout = 300;
OnContextCreated();
}
#endregion
'command.CommandTimeout = 0;'将会是无限的? –
零是无限超时。 当来自SQL SERVER实例的响应被分解为多个网络数据包时,连接将错误地结合,并且会发生一般网络错误。 – AnandMohanAwasthi
我无法在任何地方找到此类文档。谢谢。 –
- 1. 等待操作超时Win32Exception(0x80004005):等待操作超时azure
- 2. 等待操作超时
- 3. 等待操作超时
- 4. 等待操作超时ASP.NET
- 5. 等待操作超时
- 6. System.ComponentModel.Win32Exception:等待操作超时
- 7. 等待操作超时。 ASP
- 8. 等待操作在SQL Server中超时
- 9. Linq的等待操作超时异常
- 10. Win32Exception(0x80004005):等待操作超时
- 11. asp.net mvc中的等待操作超时4
- 12. 等待操作超时 - 加长超时周期
- 13. 等待超时 - Windows
- 14. 等待不超时
- 15. WebDriver等待超时和隐式等待超时的区别?
- 16. Signalr SQL底板导致等待操作超时异常
- 17. Azure数据库上的“等待操作超时”故障排除
- 18. SQL Azure:SSL提供程序,错误:0 - 等待操作超时
- 19. EF代码优先 - System.ComponentModel.Win32Exception:等待操作超时
- 20. Selenium.click超时等待动作完成
- 21. 异步等待超时
- 22. 等待UDPClient.ReceiveAsync与超时
- 23. RabbitMQ等待超时消息
- 24. 超时30秒后,等待
- 25. 等待MongoConnection的超时
- 26. Websocket等待超时消息
- 27. net.spy.memcached.OperationTimeoutException:超时等待值
- 28. Firefox的等待超时[WatiN]
- 29. innodb锁定等待超时
- 30. QTime或QTimer等待超时
回顾你的代码。检查你的SQL查询,这得花多少CPU服用和资源.. –