[英]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.