Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

API CRM connection not working for XRM.SDK.dll(8.0)

Posted on by 435

Hi friends I need to change the code which connects API to CRM. Iam using XRM.SDK dll to connect CRM with XRM.SDL.DLL(7.0) Now I replaced this dll with 8.0 version due to this following code not working

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Client.Services;
using Microsoft.Xrm.Client;
using System.Configuration;
using System.IO;


namespace CRMServiceAPI
{
class CRMHelperClass
{
public static OrganizationService GetCRMService()
{
CrmConnection crmconnection = new CrmConnection("CRM");
return new OrganizationService(crmconnection);
}

}

}

<connectionStrings>
<add name="CRM" connectionString="Url=xxx.api.crm.dynamics.com; Username=hsh67867; Password=shs7687;" />

</connectionStrings>

Can you guys advice me what code I must change here.

Regards, 

*This post is locked for comments

  • Suggested answer
    Michel van den Brink Profile Picture
    Michel van den Brink 4,697 on at
    RE: API CRM connection not working for XRM.SDK.dll(8.0)

    Hello windyMill,

    Please take another closer look at my code example. You are entering a string value into the constructor, where as my code example is using a variable, which contains the full connection string.

    // Get ConnectionString as string
    string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Dynamics365Connection"].ConnectionString; 
    
    // Create client by passing connectionstring CrmServiceClient client = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);


  • windyMill Profile Picture
    windyMill 435 on at
    RE: API CRM connection not working for XRM.SDK.dll(8.0)

    Hi Michel,

    Thanks for your code but I am getting following error in line

    "var client = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient("Dynamics365Connection");"

    </connectionStrings>

    <add name="Dynamics365Connection" connectionString="AuthType=Office365;Username=xxxx; Password='zzzz'; Url=https://kkk.api.dynamics.com;  RequireNewInstance=True;" />

    </connectionStrings>

    Error-

    "An unhandled exception of type 'System.ArgumentNullException' occurred in Microsoft.Xrm.Tooling.Connector.dll

    Additional information: Organization cannot be null or empty."

  • Suggested answer
    Michel van den Brink Profile Picture
    Michel van den Brink 4,697 on at
    RE: API CRM connection not working for XRM.SDK.dll(8.0)

    Hey windyMill,

    Sure thing.

    Let's assume you have this ConnectionString in your app.config file

    <connectionStrings>  
        <add name="Dynamics365Connection" connectionString="AuthType=Office365;Username=jsmith@contoso.onmicrosoft.com; Password='enterpasswordhere';Url=contoso.crm.dynamics.com;RequireNewInstance=True;" />  
    </connectionStrings>  ]
    


    Then you can connect to Dynamics 365 (CRM) with this snippet:

    // Get ConnectionString as string
    string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Dynamics365Connection"].ConnectionString; 
    // Create client
    var client = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);
    
    // Make sure it's connected and ready for use 
    if (client.IsReady)
    {
        // TODO: Add your code here
    }
    else
    {
        // If it's not ready that means the connection failed, report the error
        Console.Error.WriteLine("Failed to connect!");
        if (client.LastCrmException != null)
        {
            Console.Error.WriteLine(client.LastCrmException.Message);
        }
        else if (client.LastCrmError != null)
        {
            Console.Error.WriteLine(client.LastCrmError);
        }
    }
    

  • windyMill Profile Picture
    windyMill 435 on at
    RE: API CRM connection not working for XRM.SDK.dll(8.0)

    Thanks for your reply Michel .

    But I am not getting how implement it my code. Can you pls give me a code snippet . So that i can pull credential from app config and use to connect CRM

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: API CRM connection not working for XRM.SDK.dll(8.0)

    What version of CRM are you running?

    If you are running CRM 8.0-8.2 download the appropriate sdk from the Microsoft web site:

    www.microsoft.com/.../details.aspx

    If you are running CRM 9.0 or above, download the sdk via the nuget packages listed below:

    docs.microsoft.com/.../download-tools-nuget

    Hope this helps.

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: API CRM connection not working for XRM.SDK.dll(8.0)

    Hi,

    Which version of crm are you using .

    Please check the release history based on sdk version better to use.

    msdn.microsoft.com/.../dn481567.aspx

    Please check accordingly.

  • Suggested answer
    Michel van den Brink Profile Picture
    Michel van den Brink 4,697 on at
    RE: API CRM connection not working for XRM.SDK.dll(8.0)

    Hello,

    This SDK is an outdated version which might not be the best fit for your use case.

    Take a look at the new XrmTooling library from Microsoft, which is becoming the recommended way to connect to Dynamics 365 in C#

    For this you ceal use the Microsoft.CrmSdk.XrmTooling.CoreAssembly NuGet package

    https://www.nuget.org/packages/Microsoft.CrmSdk.XrmTooling.CoreAssembly/ 

      

    How to use it:

    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/xrm-tooling/use-crmserviceclient-constructors-connect 

    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/xrm-tooling/use-connection-strings-xrm-tooling-connect

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans