简体   繁体   English

Dynamics CRM SDK Context.SaveChanges 权限错误

[英]Dynamics CRM SDK Context.SaveChanges permission error

I have looked around a lot of MS Dynamics CRM blogs and SO questions and tried all the solutions but they haven't worked.我环顾了很多 MS Dynamics CRM 博客和 SO 问题,并尝试了所有解决方案,但都没有奏效。

The problem I am facing is as follows: I am trying to loop through an excel file with company names and company type.我面临的问题如下:我正在尝试遍历一个包含公司名称和公司类型的 excel 文件。 I then find company with matching names in CRM and set values for some custom fields depending on the company type in excel.然后我在 CRM 中找到具有匹配名称的公司,并根据 excel 中的公司类型为一些自定义字段设置值。 When I do this though code for a single company it works fine however when I try to run a loop for a large number of companies I am constantly getting:当我通过单个公司的代码执行此操作时,它工作正常但是当我尝试为大量公司运行循环时,我不断得到:

SecLib::CrmCheckPrivilege failed. SecLib::CrmCheckPrivilege 失败。 Returned hr = -2147220943 on UserId: xxxxxx and PrivilegeType: Read.在 UserId: xxxxxx 和 PrivilegeType: Read 上返回 hr = -2147220943。

The user in question has all privilleges and is an admin user with Read/Write CAL.有问题的用户拥有所有特权,并且是具有读/写 CAL 的管理员用户。 Also like I pointed out I am able to do the updates for a single record.就像我指出的那样,我可以对单个记录进行更新。 But when run as a loop that very same record throws an error.但是当作为循环运行时,相同的记录会引发错误。

I have been unable to find a solution for this so any help would be much appreciated.我一直无法为此找到解决方案,因此非常感谢任何帮助。 I am using MS Dynamics CRM online.我在线使用 MS Dynamics CRM。

Here's my code:这是我的代码:

while (!parser.EndOfData)
{
    counter++;

    if (counter >= 20) 
    {
        try
        {
            counter = 0;
            context.SaveChanges();
        }
        catch (Exception exc) 
        {
            while (exc != null)
            {
                System.Diagnostics.Debug.WriteLine("ERROR: " + exc.Message);
                exc = exc.InnerException;
            }
            continue;
        }
    }

    //Processing row
    string[] fields = parser.ReadFields();

    foreach (string field in fields)
    {
        //TODO: Process field
        company.Add(fields[0]);
        category.Add(fields[1]);

        var currAccs = context.CreateQuery<Account>().Where(x => x.Name.Contains(fields[0])).ToList();
        if (currAccs != null)
        {
            foreach (var currAcc in currAccs)
            {
                System.Diagnostics.Debug.WriteLine("Processing: " + currAcc.Name);
                currAcc.cir_MediaOwner = false;
                currAcc.cir_Agency = false;
                currAcc.cir_AdvertiserBrand = false;

                if (fields[1].Contains("MO"))
                {
                    currAcc.cir_MediaOwner = true;
                }

                if (fields[1].Contains("A"))
                {
                    currAcc.cir_Agency = true;
                }

                if (fields[1].Contains("B"))
                {
                    currAcc.cir_AdvertiserBrand = true;
                }

                try
                {
                    context.UpdateObject(currAcc);
                }
                catch (Exception exc)
                {
                    while (exc != null)
                    {
                        System.Diagnostics.Debug.WriteLine("ERROR: " + exc.Message);
                        exc = exc.InnerException;
                    }
                    continue;
                }
            }
        }

        break;
    }
}

It is possible that you have either a Workflow or Plugin Step related to account and create/update message, impersonated with an User without the proper privileges.您可能有一个与帐户和创建/更新消息相关的工作流或插件步骤,冒充没有适当权限的用户。

For workflows, these could have the option "execute as: the owner of the workflow" ( link )对于工作流,这些可以有选项“执行为:工作流的所有者”( 链接

For plug-in steps, these have an option "Run in User's Context" that can be set to a fix user ( link )对于插件步骤,这些有一个选项“在用户的上下文中运行”,可以设置为修复用户( 链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM