Connecting to CRM from other applications using CrmConnection class – CRM 2015
Assume that you have an ASP.Net web application and you want to retrieve Contacts from CRM and display in a grid.
Before CRM 2015, to establish a connection with CRM we need to create a service proxy with user credentials (Refer article).
With CRM 2015, we can use “Connection Strings” to connect to the CRM server from external application.
You define the CRM connection strings in <web.config> or <app.config> as below
<configuration>
<connectionStrings>
<!– Online using Office 365 –>
<!– <add name=”Server=CRM Online, organization=contoso, user=someone” connectionString=”Url=https://contoso.crm.dynamics.com; Username=someone@contoso.onmicrosoft.com; Password=password;”/> –>
<!– Online using Microsoft account (formerly Windows Live ID) –>
<!– <add name=”Server=CRM Online, organization=contoso, user=someone@example.com” connectionString=”Url=https://contoso.crm.dynamics.com; Username=someone@example.com; Password=password; DeviceID= DevicePassword= “/>–>
<!– 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;”/> –>
<!– On-premises using Windows integrated security –>
<!–<add name=”Server=myserver, organization=AdventureWorksCycle” connectionString=”Url=http://myserver/AdventureWorksCycle;”/>–>
<!– On-premises (IFD) with claims –>
<!–<add name=”Server=litware.com, organization=contoso, user=someone@litware.com” connectionString=”Url=https://contoso.litware.com; Username=someone@litware.com; Password=password;”/>–>
</connectionStrings>
</configuration>
And you can establish connection in your code as below
// ‘CRMOnline’ is ConnectionString name defined in <web.config> or <app.config>
var connection = new CrmConnection(“CRMOnline”);
var service = new OrganizationService(connection);
var context = new CrmOrganizationServiceContext(connection);
Refer MSDN article for more details
🙂