1

I have troubles with CRM2011:

All new users created in the Active Directory have bad performances when the code tries to retrieve data from the database via linq queries using the IOrganizationService. The new users have the same rights than the old users.

Here is some code for better understanding. Activity is an ActivityPointer, I try to get all the attachments linked to it: ( the slow part is when i try to use one of the items of the ActivityAttachments property)

foreach (var attachment in activity.ActivityAttachments)
                        {
                             //Do stuff
                        }

ActivityAttachments is the result of a linq query using the datacontext

        public IEnumerable<ActivityMimeAttachment> ActivityAttachments
    {
        get { return Datacontext.ActivityMimeAttachmentSet.Where(a => a.ObjectId != null && a.ObjectId.Id == Id).Select(a => new ActivityMimeAttachment(a)); }
    }

and the datacontext is my datamodel - created and stored for each user as my crmservice , instance of my organizationservice

private static readonly ConcurrentDictionary<string, LeDataModel> _dataModels = new ConcurrentDictionary<string, LeDataModel>();
        protected LeDataModel Datacontext
        {
            get
            {
                LeDataModel _model;

                if (HttpContext.Current != null)
                {
                    var currentUser = HttpContext.Current.User.Identity.Name;

                    if (!_dataModels.TryGetValue(currentUser, out _model))
                    {
                        _model = new LeDataModel(CrmService) { MergeOption = MergeOption.NoTracking };
                        _dataModels.TryAdd(currentUser, _model);
                    }
                }
                else
                {
                    _model = AdminDataContext;
                }

                return _model;
            }
        }

protected OrganizationService CrmService
        {
        get
        {
            OrganizationService _service;

            if (HttpContext.Current != null)
            {
                var currentUser = HttpContext.Current.User.Identity.Name;

                if (!_services.TryGetValue(currentUser, out _service))
                {
                    _service = new OrganizationService("Crm");
                    _services.TryAdd(currentUser, _service);
                }
            }
            else
            {
                _service = AdminCrmService;
            }

            return _service;
        }
    }

I think, the problem is not due to code because it works fine for some users and is only slow for new users. I have compared the new/old users in the CRM and in the AD and everything seems equal. Can someone knows how the authentication is done by the CRM ? Do you have an other idea ?

  • are there any error logs or event viewer logs around the times of the slow logins? Have any changes been made for new users as compared to old users? Permission changes or the like? – user1666620 Dec 09 '15 at 16:27
  • Hello,yes there are some logs, but I do not think it's relevant because the old user have it too ( but far less) : System.Web.HttpException (0x80004005): The client disconnected. ---> System.Web.UI.ViewStateException: Invalid viewstate. ---> Sytem.FormatException: Invalid length for a Base-64 char array. – Sylvain Ava Dec 09 '15 at 16:33
  • Exactly how much is "far less"? Throwing and catching exceptions can be quite expensive in terms of resources - if the new users have the same errors, but a lot more of them, then that is probably the source of the performance issues. – user1666620 Dec 09 '15 at 16:37
  • The issue happens often with new users but almost never with the old ones. But the exception is not thrown on this very own part of code, It seems to be thrown during the creation of the ASP Page – Sylvain Ava Dec 09 '15 at 16:44
  • Again, you need to define "often". Is it once on every login? 10 times? a hundred? – user1666620 Dec 09 '15 at 16:45
  • No less than one exception on every login – Sylvain Ava Dec 09 '15 at 16:46
  • I still think that could be a cause of the performance. You need to find the cause and deal with it. – user1666620 Dec 09 '15 at 16:48
  • Of course, It's a good idea. if my app is more robust, It will be better. I can work on it but, I think the problem is somewhere else ... – Sylvain Ava Dec 09 '15 at 16:51

1 Answers1

0

From your comments about how new users are suffering the same exceptions as old users, except far more of them, I think this is the cause of your performance issues for new users.

Find the cause of the exceptions and fix them, and your performance should improve.

Read this http://blogs.msdn.com/b/ricom/archive/2006/09/25/771142.aspx

and this

How expensive are exceptions in C#?

Community
  • 1
  • 1
user1666620
  • 4,800
  • 18
  • 27