CRM 2011 -使用SSIS连接到CRM -状态401:未授权
本文关键字:CRM 授权 状态 连接 2011 使用 SSIS | 更新日期: 2023-09-27 17:50:40
我正在尝试使用SQL 2008 R2集成服务连接到CRM 2011 -目标是,将数据加载到CRM。参考博客MSDN博客,我试图建立一个连接到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 message,> WebResponse response, Stream responseStream, Boolean asyncall)在System.Web.Services.Protocols.SoapHttpClientProtocol。调用(String methodName, Object[])参数)在CRM.Proxy.CrmSdk.CrmService。创建(BusinessEntity实体)在ScriptMain。Input0_ProcessInputRow (Input0Buffer行)在UserComponent。Input0_ProcessInput (Input0Buffer缓冲)在UserComponent。ProcessInput(Int32 InputID, PipelineBuffer Buffer)在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
您正在使用默认凭证,那么运行SSIS作业的用户是具有正确权限的CRM用户吗?
作为测试,您可以尝试硬编码凭证。像这样:
service.Credentials = new NetworkCredential("username", "password", "domain");
还有,您使用2007端点有什么原因吗?如果/当你升级到CRM 2013,它会被弃用吗?