Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
Posted on by 437

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
    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
    437 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
    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
    437 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 - MVP Profile Picture
    30,188 Moderator 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
    50,091 Moderator 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
    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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans