无法通过连接字符串连接到 Dynamics CRM Online。组织不能为 null 或为空。参数名称:组织名称

Unable to connect via connection string to Dynamics CRM Online. Organization cannot be null or empty. Parameter name: Organization Name

我正在尝试使用 Microsoft.CrmSdk.XrmTooling.CoreAssembly v 8.2.0.5

通过连接字符串连接到 CRM Online

按照 MSDN 中的指南,我的连接字符串如下所示:AuthType=Office365;Username=jsmith@contoso.onmicrosoft.com; Password=passcode;Url=https://contoso.crm.dynamics.com

但是,我收到错误 System.ArgumentNullException 类型的异常消息:Organization cannot be null or empty。 参数名称:组织名称

来源:Microsoft.Xrm.Tooling.Connector

public void GetClient()
{
    try
        {
            var client = new CrmServiceClient(GetConnectionString());
            Assert.IsTrue(client.IsReady);

        }
        catch (Exception ex)
        {
            throw;
        }

}
private string GetConnectionString()
{
    try
    {
        var connectionString = default(string);

        try
        {
            connectionString = "AuthType:Office365;Url=https://MyCRM.crm4.dynamics.com; UserName=ATMain@MyOrganization.com;Password=MySecretPasscode;"; 
        }
        catch (Exception ex)
        {
            throw;
        }
        return connectionString;
    }
    finally
    {

    }
}

你必须这样写连接字符串:

 <add name="Server=CRM Online, 
organization=contoso, user=someone"
connectionString="Url=https://contoso.crm.dynamics.com;
Username=someone@contoso.onmicrosoft.com; Password=password; authtype=Office365"/> -->

sample to-do

希望对您有所帮助!

问题在这里:

"AuthType:Office365; ..."

这应该是:

"AuthType=Office365; ..."

您仍然需要将组织名称放在 url 的末尾,因此它应该类似于 this:Url=https://contoso.crm.dynamics.com/contoso;