Connect to MS CRM 2011 Online using C# Sdk

Posted: May 23, 2013 in Code Snippets, CRM 2011

Create record in MS CRM 2011 Online using C# Code

Add "Microsoft.Xrm.Sdk" reference from your sdk bin folder.

Then add the following namespaces
1) using Microsoft.Xrm.Sdk;
2) using Microsoft.Xrm.Sdk.Client;
3) using System.ServiceModel.Description;
4) using System.Web.Services.Protocols;

Finally add the below code :

                ClientCredentials cre = new ClientCredentials();
                cre.UserName.UserName = "<username>";
                cre.UserName.Password = "<password>";

                Uri serviceUri = new Uri("https://<orgname>");

                OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, cre, null);
                IOrganizationService service = (IOrganizationService)proxy;

                Entity ent = new Entity("<entitySchemaName>");
                ent.Attributes["new_name"] = "Created from Console App4";
            catch (SoapException ex)

            catch (Exception ex)


Happy Coding 🙂

  1. Nagarjuna says:

    Thanks sir, very nice article.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s