[英]CRM 2011 - Connect to CRM using SSIS - status 401: Unauthorized
我正在尝试使用SQL 2008 R2 Integration Services连接到CRM 2011-目标是将数据加载到CRM中。 提到Blog 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.Invoke(String methodName,Object []参数)在System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage消息,> WebResponse响应,流responseStream,布尔asyncCall)。 Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput上的ScriptMain.Input0_ProcessInputRow(Input0Buffer行)在UserComponent上的Proxy.CrmSdk.CrmService.Create(BusinessEntity实体) (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
您使用的是默认凭据,所以运行SSIS作业的用户是否是具有正确特权的CRM用户?
作为测试,您可以尝试对凭据进行硬编码。 像这样:
service.Credentials = new NetworkCredential("username", "password", "domain");
此外,是否有任何原因使您使用2007终结点计算机。 如果/当您升级到CRM 2013时将不推荐使用?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.