• Home
  • Blog
  • About Me
  • Home
  • Blog
  • About Me
Dynamics 365

Simple Dynamics CRM Console Application

By Joe Gill  Published On 10th September 2016

This is a quick tip on how to create a simple Dynamics CRM console application in C# that connects to Dynamics CRM 2016 and creates an account record. There is some sample  code in the SDK that demonstrates how to do this but this sample is even simpler.

static void Main(string[] args)
{
    // Get the CRM connection string and connect to the CRM Organization
    CrmServiceClient crmConn = new CrmServiceClient(ConfigurationManager.ConnectionStrings["CRM"].ConnectionString);
    IOrganizationService crmService = crmConn.OrganizationServiceProxy;
 
    Entity acc = new Entity("account");
    acc["name"] = "Joe's New Account";
    crmService.Create(acc);
                
}

 

Firstly create a new console application in Visual Studio and then go to the NuGet Package Manager option and install the Microsoft Dynamics CRM 2016 SDK Xrm Tooling Package.

Dynamics CRM Console Application NuGet


Edit the app.config file in your project and add a connectionsStrings section with your CRM connection string.
 
  <connectionStrings>
    <add name="CRM" connectionString="AuthType=Office365;Url=https://joegilltest.crm4.dynamics.com; Username=joe@joegilltest.onmicrosoft.com; Password=MyPassword" />
  </connectionStrings>
 
 
Now add a reference to the System.Configuration assembly in your project so you can access your config file from code.
 
Dynamics CRM Console Application Assembly References
 

Add the following namespaces to your code
 
using System.Configuration;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Tooling.Connector;
 
Now add the code shown at the top to your main method. When you run your Dynamics CRM console application it will connection to CRM and create an account record.
 
 
Dynamics CRM Console Application New Account
 
 
 

Leave A Reply Cancel reply

You must be logged in to post a comment.

How to add an Editable Grid to a Dynamics CRM Form
Previous Article
Message Listener with No Code Json Parsing
Next Article