Follow the below steps,
Step 1: Open Visual Studio and Click on New Project. Click on Visual C# and select Console Application.
Give Name to the Project and click on OK.

Step 2: Goto Visual Studio Tools -> NuGet Package Manager and click on Package Manger Console.

Step 3: In Package Manager Console, Copy & Paste the below command to get the required CRM SDK Dlls and press Enter.
Click here to know the Latest version of the CRM Dlls.
Install-Package Microsoft.CrmSdk.CoreTools -Version 9.0.0.7

Step 4: Latest CRM SDK Dlls are installed in the project’s bin\coretools folder. You can also see the success message in Package Manager Console.

Step 5: Right Click on References and navigate to bin\coretools folder.
Add the below Dlls to the Visual Studio project.
Microsoft.Crm.Sdk.Proxy.dll
Microsoft.Xrm.Sdk.dll

And also add the below and click on OK,
System.Runtime.Serialization
System.ServiceModel

Step 6: Add the below namespaces.
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Crm.Sdk.Messages;
using System.Net;
using System.ServiceModel.Description;

Step 7: Copy and Paste the below Code in Main method.
IOrganizationService organizationService = null;
try
{
ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = "<ProvideUserName>@<ProvideYourOrgName>.onmicrosoft.com";
clientCredentials.UserName.Password = "<ProvideYourPassword>";
// For Dynamics 365 Customer Engagement V9.X, set Security Protocol as TLS12
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Get the URL from CRM, Navigate to Settings -> Customizations -> Developer Resources
// Copy and Paste Organization Service Endpoint Address URL
organizationService = (IOrganizationService)new OrganizationServiceProxy(new Uri("https://<ProvideYourOrgName>.api.<CRMRegion>.dynamics.com/XRMServices/2011/Organization.svc"),
null, clientCredentials, null);
if (organizationService != null)
{
Guid userid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).UserId;
if (userid != Guid.Empty)
{
Console.WriteLine("Connection Established Successfully...");
}
}
else
{
Console.WriteLine("Failed to Established Connection!!!");
}
}
catch (Exception ex)
{
Console.WriteLine("Exception caught - " + ex.Message);
}
Console.ReadKey();
Step 8: Right click on the solution and build it. If build is succeeded, Run the application to see the below Message.

Note:
Problem: If you face any build issues like the below, while building the project, then use the below solution and resolve it.

Solution: Follow the below steps to resolve the problem.
- Change the Project’s Dot Net Framework from 4.5 to 4.5.2, this change is required because latest CRM SDK Dlls needs the 4.5.2 version of Dot Net Framework.

2. Click on Yes and build the project.

For more info Click here.
Hope you have successfully connected to Dynamics CRM Online Version 9.X :):):)
Like this:
Like Loading...