【问题标题】:Exception thrown when there is load on database数据库负载时抛出异常
【发布时间】:2014-07-02 11:50:13
【问题描述】:

我正在开发电子商务系统 (NopCommerce)。我使用的技术是 Asp.Net Mvc3sql server 2008 下订单时抛出异常(不是每次,而是在数据库负载时)

将产品添加到订单后,我使用以下功能更新库存

_productService.AdjustInventory(sc.ProductVariant, true, sc.Quantity, sc.AttributesXml);

Error while placing order. Error 0: Error: An error occurred while updating the entries. See the inner exception for details.. Full exception: System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

可能有很多客户在线或我正在更新 ProductVariant,这是一个漫长的过程(需要 10-12 分钟)。那时只抛出这个异常。

避免此异常的任何解决方案。

【问题讨论】:

  • 是的,修复更新过程,使其不会运行 10-12 分钟
  • 您的代码超时。在 NopCommerce 中,我没有看到任何事情需要这么长时间。您可能需要检查您的数据库、更新索引、统计信息等。

标签: asp.net-mvc entity-framework asp.net-mvc-3 sql-server-2008 nopcommerce


【解决方案1】:

尼丁,

问题在于超时,因为默认情况下,SQL“语句”的超时设置为 30 秒。如果 SQL Server 完成任务的时间超过 30 秒,您将收到超时。您可能想自己设置超时。超时属性称为 CommandTimeout,它是 SqlCommand 对象的一个​​属性。

using (SqlCommand myCommand = new SqlCommand())
{
   // Set the new command timeout to 60 seconds
   // in stead of the default 30
   myCommand.CommandTimeout = 60;
}

此问题的以下三个原因可能是

  1. 某处出现死锁

  2. 数据库的统计信息和/或查询计划缓存不正确

    3.查询太复杂,需要调优

在这里查看答案Check Out This

希望对你有帮助......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 2012-12-24
    • 2020-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多