0

I am working on E-Commerce system (NopCommerce).Technology I am using is Asp.Net Mvc3 and sql server 2008 While placing order Exception is thrown (Not every time but when there is load on database)

After adding Product to order I use following function to update Inventory

_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.

There might be case that many customers are online or I am updating ProductVariant which is lengthy process(takes 10-12 mins). At that time only this exception is thrown.

Any solutions to avoid this exception.

Marco Regueira
  • 1,045
  • 8
  • 17
Nitin Varpe
  • 10,450
  • 6
  • 36
  • 60
  • 2
    Yes fix the update process so it doesn't run for 10-12min – 3dd Jul 02 '14 at 11:53
  • Your code is timing out. I've not seen anything take that long in NopCommerce. You probably need to check your database, update indexes, stats etc. – DavidG Jul 02 '14 at 11:57

1 Answers1

1

Nitin,

The problem is time out because by default the timeout of an SQL 'statement' is set to 30 seconds. If SQL Server takes more than 30 seconds to complete your task, you'll receive a timeout. You may want to set the timeout yourself. The timeout property is called CommandTimeout, it's a property of the SqlCommand object.

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

Below Three Reasons for this issue may be

  1. There's a deadlock somewhere

  2. The database's statistics and/or query plan cache are incorrect

    3.The query is too complex and needs to be tuned

See the Answer here Check Out This

Hope it helps........

Community
  • 1
  • 1
Anto king
  • 1,222
  • 1
  • 13
  • 26