Developer forum

Forum » Development » SQL deadlock calling GetByProductIDs functions

SQL deadlock calling GetByProductIDs functions

Jose Caudevilla
Reply

Hi,

 

Today i get the following error related the sql transactions:

2021-10-05 09:17:18.730: Error executing razor template (Designs/Rapido/Paragraph/ProductosRelacionados_NAS_B2C.cshtml) System.Data.SqlClient.SqlException (0x80131904): Transaction (Process ID 681) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows)
at System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)
at System.Data.SqlClient.SqlDataReader.Read()
at Dynamicweb.Ecommerce.Products.ProductRepository.GetProductsBySql(CommandBuilder query, Boolean doRefactoring, Boolean bulkFill, Boolean useAssortments)
at Dynamicweb.Ecommerce.Products.ProductService.GetByProductIDs(String[] productIds, Boolean doRefactoring, String productLanguageId, Boolean bulkFill, Boolean useAssortments)
at CompiledRazorTemplates.Dynamic.RazorEngine_e2492a0701ac48789a89c641c4f556f9.<RenderProducts>b__42_0(TextWriter __razor_helper_writer) in \Files\Templates\Designs\Rapido\Paragraph\ProductosRelacionados_NAS_B2C.cshtml:line 1705
at CompiledRazorTemplates.Dynamic.RazorEngine_e2492a0701ac48789a89c641c4f556f9.Execute() in D:\Dynamicweb.net\Files\Templates\Designs\Rapido\Paragraph\ProductosRelacionados_NAS_B2C.cshtml:line 1572
at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
at Dynamicweb.Rendering.Template.RenderRazorTemplate() ClientConnectionId:c75825bc-f6b2-4f4b-a42d-45f312b46bd5 Error Number:1205,State:51,Class:13
2021-10-05 09:17:18.887: Request headers: [   "Connection",   "Transfer-Encoding",   "Host",   "User-Agent" ]
2021-10-05 09:17:18.887: Request item keys: [   "DynamicwebLiveIntegrationIsIntegrationActive",   "owin.Environment",   "EcomCart:CustomCartContext",   "Rendering.Items.ItemRelationListEditor_Paragraph_3186",   "MS_HttpRequestMessage",   "AspSession",   "PermissionContextStack",   "Rendering.Items.ItemRelationListEditor_Paragraph_2647",   "Dynamicweb.OMC.VisitContext",   "AspSessionIDManagerInitializeRequestCalled",   "PagePermissionWithInheritanceFrontend2202",   "alternateUrlKey",   "ExecutionTableMapper",   {},   "DWPAGEVIEW",   "Rendering.Items.ItemRelationListEditor_Paragraph_2429",   "Dynamicweb.Environment.Web",   "Dynamicweb.Tracking.Tracker" ]
2021-10-05 09:17:18.902: Request form: []

 

The error is localiced inside this fragment of code:

 else if ((Model.Item.GetValue("Products") != null) && (Model.Item.GetValue("Products") != "")) {


        List<string> productIds = new List<string>();
        
        foreach(var product  in  (Model.Item.GetValue("Products") as List<ProductViewModel>))
        {
            productIds.Add(product.Id);
        }

        var producObject = productService.GetByProductIDs(productIds.ToArray(),true,"LANG1",true,true);

 

We need to use the product Object instead of the productModel.

Is there any way to avoid deadlocks in this type of calls ?

 

Regards,

Jose.


Replies

 
Nicolai Pedersen
Reply

I am sure you do not need to product object.

But if you do, get the product instance using GetProductById(string productId, string productVariantId, string productLanguageId, bool useAssortments) on the product service instead.

That will give you the cached product. GetByProductIDs talks to the database and you do not want that here.

BR Nicolai

 

You must be logged in to post in the forum