【问题标题】:CRM 2011 - Connect to CRM using SSIS - status 401: UnauthorizedCRM 2011 - 使用 SSIS 连接到 CRM - 状态 401:未经授权
【发布时间】:2014-03-17 12:33:24
【问题描述】:

我正在尝试使用 SQL 2008 R2 集成服务连接到 CRM 2011 - 目标是将数据加载到 CRM 中。 参考博客MSDN Blog,我尝试建立与 CRM 的连接并将数据加载到其中。

一切正常,除了脚本组件。 这是我的脚本组件中的代码:

public class ScriptMain : UserComponent
{
    CrmService service = new CrmService();

    public override void PreExecute()
{
        base.PreExecute();

        CrmService service = new CrmService();
        service.Credentials = System.Net.CredentialCache.DefaultCredentials;
        service.Url = "http://crm2011dev.myOrg.local/MSCrmServices/2007/CrmService.asmx";

        CrmAuthenticationToken token = new CrmAuthenticationToken();
        token.OrganizationName = "myOrg";
        service.CrmAuthenticationTokenValue = token;
        service.PreAuthenticate = true;          
    }

    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        contact Kontakt = new contact();

        Kontakt.firstname = Row.FirstName;
        Kontakt.lastname = Row.LastName;
        Kontakt.telephone1 = Row.Phone;
        Kontakt.emailaddress1 = Row.Email;

        service.Create(Kontakt);
    }
}

但是当我执行包的时候,出现如下错误:

请求失败,HTTP 状态为 401:未经授权。 在 System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage 消息,> WebResponse 响应,流 responseStream,布尔 asyncCall) 在 System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(字符串方法名,对象 [] 参数) 在 CRM.Proxy.CrmSdk.CrmService.Create(BusinessEntity 实体) 在 ScriptMain.Input0_ProcessInputRow(Input0Buffer 行) 在 UserComponent.Input0_ProcessInput(Input0Buffer 缓冲区) 在 UserComponent.ProcessInput(Int32 InputID,PipelineBuffer 缓冲区) 在 Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32 inputID, PipelineBuffer 缓冲区)

这不可能,我想,因为运行执行的用户拥有完整的 CRM 权限(CRM 中的系统管理员角色)!

所以我尝试直接在“Input0_ProcessInputRow”部分实现代码:

public class ScriptMain : UserComponent
{
    CrmService service = new CrmService();

    public override void PreExecute()
    {
        base.PreExecute();               
    }

    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
    // here the part from the PreExecute() section:
        CrmService service = new CrmService();
        service.Credentials = System.Net.CredentialCache.DefaultCredentials;
        service.Url = "http://crm2011dev.myOrg.local/MSCrmServices/2007/CrmService.asmx";

        CrmAuthenticationToken token = new CrmAuthenticationToken();
        token.OrganizationName = "myOrg";
        service.CrmAuthenticationTokenValue = token;
        service.PreAuthenticate = true;



        contact Kontakt = new contact();

        Kontakt.firstname = Row.FirstName;
        Kontakt.lastname = Row.LastName;
        Kontakt.telephone1 = Row.Phone;
        Kontakt.emailaddress1 = Row.Email;

        service.Create(Kontakt);
    }
}

...它的工作原理! 所以这不可能是一个简单的权限问题。

看来,脚本组件没有将凭据从“PreExecute”传递到“Input0_ProcessInputRow”......我该如何解决这个问题?

有人知道吗?提前致谢!

st4ff

【问题讨论】:

    标签: c# ssis dynamics-crm-2011


    【解决方案1】:

    您使用的是默认凭据,那么运行 SSIS 作业的用户是具有正确权限的 CRM 用户吗?

    作为测试,您可以尝试对凭据进行硬编码。像这样的:

    service.Credentials =  new NetworkCredential("username", "password", "domain");
    

    另外,您是否有任何理由使用 2007 端点。如果/当您升级到 CRM 2013 时,它将被弃用?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-14
      • 2018-01-25
      相关资源
      最近更新 更多