Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Scott Sanzenbacher 5 posts 75 karma points
    Mar 06, 2016 @ 20:07
    Scott Sanzenbacher
    0

    SaveAndPublishWithStatus Deadlock And Duplicates

    I have code that is looping through records which I grab from the database with a direct fetch, then it migrates these to Umbraco Content using the ContentService. They have relationships to other content using both a multinode treepicker and a content picker. I save off all relationship data (Name and Id) to dictionaries before the for loop in order to avoid any unnecessary searches within a loop. I check ahead of time and I have 310 records that should be migrated, but I keep getting an error saying that there was a deadlock and I get duplicates in the saved content. I've run the same code at times and gotten different results, every once in a great while it actually works fine, but usually I just end up with different numbers of duplicates. Additionally, after I do get the exception returned to me, the process keeps running, as I can see more items getting created. It seems like there could, internally, be a retry that is happening when it fails to save properly. Maybe.

    The code I'm using looks like this:

                    foreach (var physician in existingPhysicians)
                    {
                        int locationId = -1;
                        int specialty1Id = -1;
                        int specialty2Id = -1;
    
                        if (!string.IsNullOrWhiteSpace(physician.LocationName))
                        {
                            locationDictionary.TryGetValue(physician.LocationName, out locationId);
                        }
    
                        if (!string.IsNullOrWhiteSpace(physician.Specialty1))
                        {
                            specialtyDictionary.TryGetValue(physician.Specialty1, out specialty1Id);
                        }
    
                        if (!string.IsNullOrWhiteSpace(physician.Specialty2))
                        {
                            specialtyDictionary.TryGetValue(physician.Specialty2, out specialty2Id);
                        }
    
                        var specialtyIds = string.Join(",", new List<int?>() { specialty1Id > 0 ? (int?)specialty1Id : null, specialty2Id > 0 ? (int?)specialty2Id : null }
                            .Where(i => i.HasValue).ToArray());
    
                        var physicianContent = cs.CreateContent(physicianName, physicianNode, "physician");
    
                        /* Set a bunch of properties */
                        physicianContent.SetValue("specialty1", specialtyIds);
                        physicianContent.SetValue("location", locationId > 0 ? locationId.ToString() : "");
                        var attempt = cs.SaveAndPublishWithStatus(physicianContent);
    
                        if(!attempt.Success)
                        {
                            throw attempt.Exception ?? new Exception(string.Join(",", attempt.Result.InvalidProperties.Select(p => p.Key)));
                        }
                    }
    
  • Scott Sanzenbacher 5 posts 75 karma points
    Mar 06, 2016 @ 20:11
    Scott Sanzenbacher
    0

    By the way, this is the error I'm getting: Transaction (Process ID 54) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

    Obviously, the Process ID changes.

  • Scott Sanzenbacher 5 posts 75 karma points
    Apr 13, 2016 @ 13:37
    Scott Sanzenbacher
    0

    Is there any way at all to get any sort of input on this?

  • Scott Sanzenbacher 5 posts 75 karma points
    Apr 21, 2016 @ 16:21
    Scott Sanzenbacher
    0

    Has anyone else seen similar behavior using the ContentService? Is there something I might be doing wrong here?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies