Open Closed

Recursive inserting values in tables #11064


0
uabel created

We have in our Application.dll a recursive call with several database inserts/updates. After some time the error comes that 'The underlying provider failed on Open', which probably has to do with the many open and close of the database connections. How can we work around this problem? We need to write values to different tables.


5 Answer(s)
  • 0
    ismcagdas created
    Support Team

    Hi @uabel

    1. Is it possible to share the app service you are having this problem
    2. Could you also share your Abp NuGet package version ?

    Thanks,

  • 0
    uabel created

    It is a very long function with several calls.

    ` private void HieararchyWalk(List<QMP3.CoreData.CoreData> hierarchy, List

            if (hierarchy != null)
            {
                foreach (var item in hierarchy)
                {
                    newParentId = item.ParentId;   
                    Logger.Debug("Id: " + item.Id + " Nummer: " + item.Nr);
                    List<CoreDataVersion> versions = new List<CoreDataVersion>();   
                    if (!allLanguages)
                    {
                        var element = _coreDataVersionRepository.GetAll().Where(r => r.CoreDataId == item.Id && r.GlobalLanguageId == defaultLanguage.Id)
                                .OrderByDescending(r => r.State == State.Freigegeben).ThenByDescending(s => s.Revision).FirstOrDefault();
                        if (element != null)
                        {
                            versions.Add(element);
                        }
                    }
                    else
                    {
                        foreach (var lang in _globalLanguageRepository.GetLanguages())
                        {
                            var element = _coreDataVersionRepository.GetAll().Where(r => r.CoreDataId == item.Id && r.GlobalLanguageId == lang.Id)
                                .OrderByDescending(r => r.State == State.Freigegeben).ThenByDescending(s => s.Revision).FirstOrDefault();
                            if (element != null)
                            {
                                versions.Add(element);
                            }
                        }
                    }
                    
                    item.CoreDataVersions = versions;
                    //item.CoreDataVersions = _coreDataVersionRepository.GetAll().Where(r => r.CoreDataId == item.Id).ToList();
                    //.Where(r => r.CoreDataId == item.Id)
                    //.OrderBy(s => s.State == State.Freigegeben)
                    //.ThenByDescending(s => s.Revision).ToList();
                    bool versionsToCopy = false;
                    
                    foreach (var version in item.CoreDataVersions)
                    {
                        var newElement = new CopiedElement();
                        counter++;
                        newParentId = CopyElement(version, item, newParentId, versionsToCopy);
                        newElement.Label = String.Concat(item.Nr, " ", version.Label);
                        newElement.Sprache = version.GlobalLanguage.Label;
                        copiedElements.Add(newElement);
                        versionsToCopy = true;
                    }
                    foreach (var ele in item.Children)
                    {
                        ele.ParentId = newParentId;
                    }
                    CoreDataIds.Add(newParentId.Value);
                    HieararchyWalk(item.Children, CoreDataIds, allLanguages);
                }
            }
        }
        public GetServiceOutput CopyStructure(GetServiceInput input)
        {
            List<QMP3.CoreData.CoreData> hierarchy = new List<QMP3.CoreData.CoreData>();
            var test = _coreDataRepository.GetAll().ToList();
            hierarchy = test
                            .Where(c => c.Id == input.CoreDataId)
                            .Select(c => new QMP3.CoreData.CoreData()
                            {
                                Id = c.Id,
                                Nr = c.Nr,
                                DataType = c.DataType,
                                Color = c.Color,
                                MenuId = c.MenuId,
                                Publish = c.Publish,
                                ParentId = c.ParentId,
                                CoreDataVersions = c.CoreDataVersions,
                                Children = GetChildren(test, c.Id)
                            })
                            .ToList();
            var coreDataIdsToDelete = new List<int>();
            defaultLanguage = _globalLanguageRepository.GetDefaultLanguage();
            HieararchyWalk(hierarchy, coreDataIdsToDelete, input.AllLanguages);
            return new GetServiceOutput
            {
                CopiedElements = copiedElements
            };
            //return null;
        }
        `
        
        
    
  • 0
    ismcagdas created
    Support Team

    Thanks,

    Could you also share your ABP NuGet package version ?

  • 0
    uabel created

    I'm using one of the oldest versions 0.7.5.0

  • 0
    ismcagdas created
    Support Team

    Hi,

    I wasn't expecting sucn an old version :). Is it possible to share your project via email with info@aspnetzero.com with reproduction steps ?

    We can try to optimize your code or offer you anoter solution.