web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

How to connect to CRM using SDK

Community Member Profile Picture Community Member

Once you have installed the SDK on your machine and have an environment to use, then now it is time to connect to CRM using C# so you can use workflows, plugins etc.

Steps to connect:

  • Create a console application or any other application in C# using Visual Studio.
  • Add reference to below mentioned dlls into your project. The dlls are available in bin folder of SDK:

Microsoft.Xrm.Sdk.dll
Microsoft.Crm.Sdk.Proxy.dll
Microsoft.Xrm.Tooling.Connector.dll

  • Now add these into your program by ‘using’ statements

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Tooling.Connector;

  • Before you connect to CRM you need to create the connection string to CRM. I have mentioned few samples below:

<!– Online using Office 365 –>
<!–<add name=”Server=CRM Online”
connectionString=”Url=https://myserver.crm.dynamics.com; Username=user@myserver.com; Password=password; authtype=Office365″/>–>

<!– On-premises with provided user credentials –>
<!– <add name=”Server=myserver, organization=AdventureWorksCycle, user=administrator”
connectionString=”Url=http://myserver/AdventureWorksCycle; Domain=mydomain; Username=administrator; Password=password; authtype=AD”/> –>

<!– On-premises using Windows integrated security –>
<!– <add name=”Server=myserver, organization=AdventureWorksCycle”
connectionString=”Url=http://myserver/AdventureWorksCycle; authtype=AD”/> –>

<!– On-Premises (IFD) with claims –>
<!–<add name=”Server=myserver.com, organization=contoso, user=someone@myserver.com”
connectionString=”Url=https://contoso.myserver.com/contoso; Username=someone@myserver.com; Password=password; authtype=IFD”/>–>

  • Now it is time to instantiate the CrmServiceClient Class with the connection string.

CrmServiceClient conn = new CrmServiceClient(ConfigurationManager.ConnectionStrings[“Server=CRM Online”].ToString());

var _orgService = (IOrganizationService)conn.OrganizationServiceProxy;

Now using the _orgService object you can create queries to fetch data or can also use to Insert/Update/Delete data into CRM.



This was originally posted here.

Comments

*This post is locked for comments