Connect to the Microsoft Dynamics CRM Server
[Applies to: Microsoft Dynamics CRM 4.0]
Find the latest SDK documentation: CRM 2015 SDK
Advanced Developer Extensions for Microsoft Dynamics CRM uses the concept of a connection string to connect to the Microsoft Dynamics CRM server. This is similar to the concept of connection strings used with Microsoft SQL Server. Connection strings are a natural part of the ADO.NET framework and also have native support in configuration files, including the ability to encrypt the configuration sections for maximum security. This encourages you to use a robust model in which Microsoft Dynamics CRM connections are configured at deployment time, and are not hard coded in your application. As such, all APIs in Advanced Developer Extensions for Microsoft Dynamics CRM work with a CrmConnection object, used internally by the XrmDataContext class shown in the following example, that uses a connection string to connect to the server.
You will supply this connection string in the app.config or web.config file for your project, as shown here.
<connectionStrings> <add name="Crm" connectionString="Authentication Type=Passport; Server=https://your-org-name.crm.dynamics.com/your-orgid; User ID=your-windowslive-id; Password=your-wlid-password; Device ID=your-device-id; Device Password=your-device-password"/> </connectionStrings>
The connection string is also used when you instantiate an XrmDataContext as shown here.
//Use the Microsoft Dynamics CRM Online connection string from the app.config file. var crm = new Xrm.XrmDataContext("CRMOnline");
The basic format of the connection string is the same as an OLEDB connection string. It is a series of name/value pairs separated by semicolons. The parameters listed in the following table, which can be entered in any order, are allowed.
|Authentication Type||Specifies the type of authentication. The Authentication Type parameter can have one of the following values: Integrated, AD, SPLA, or Passport.
Integrated - Used to authenticate with Microsoft Dynamics CRM using the current Windows credentials of the application. This is typically used in making prototypes and in development environments and only works with on-premises deployments in the same Active Directory domain (or trusted domain) as the Microsoft Dynamics CRM server. It does not work for Internet-facing deployments (IFDs) or with Microsoft Dynamics CRM Online.
AD - Used to specify Active Directory credentials of a specific service account. This is used for on-premises deployments and is usually used for production systems.
SPLA - Used for internet facing deployment (IFD). SPLA is an acronym for Service Provider License Agreement, which is the licensing program that partners are required to use to license Microsoft Dynamics CRM in hosting arrangements.
Passport - Used for Microsoft Dynamics CRM Online deployments. This uses the Windows Live ID mechanism, which used to be called Passport. Passport authentication cannot be used with on-premises or internet facing deployment deployments.
|Server||Specifies the URL of the Microsoft Dynamics CRM server. It can be http or https. The port is optional if it is http over port 80 or https over port 443. The server URL is typically in this form:
The organization-name is required.
|User ID||Specifies the user name of the service account that is used to connect using AD, SPLA, or Passport authentication types. It is not needed for integrated authentication. The format for this is specific to the authentication type: domain\username for AD and SPLA authentication types and a Windows Live ID for Passport authentication.|
|Password||Specifies the password of the service account that is used to connect using AD, SPLA, or Passport authentication.|
|Device ID||Specifies the device ID. Each connection to the Windows Live service requires a user-defined Device ID that can be any string from 12 to 22 characters in length. This device ID will be registered the first time an authentication is run but will be required for all subsequent authentications with the WLID specified in this connection string.|
|Device Password||Specifies the device password. Each connection to the Windows Live service requires a user-defined device password that can be any string from 12 to 22 characters in length. This device password will be registered the first time an authentication is run but will be required for all subsequent authentications with the WLID specified in this connection string. If the device ID and device password do not match the values that are registered, the authentication will fail.|
|Timeout||Specifies the time your XML Web service client waits for a synchronous XML Web service request to complete, in milliseconds.|
|Discovery URL||Specifies the Discovery URL used by your site if you are connecting to a Microsoft Dynamics CRM Online organization. To connect to Microsoft Dynamics CRM Online, the discovery service is first hit to retrieve a passport authentication ticket. This ticket indicates that a Live ID user is, in fact, authenticated to use the Microsoft Dynamics CRM Online instance.|
|PreAuthenticate||Specifies whether to use pre-authentication. This true/false parameter is passed through to the XML Web service to set Preauthenticate in the framework. Setting this value to true may affect performance.|
|Connection Sharing||Specifies whether to use connection sharing. This true/false parameter is passed through to the XML Web service to set UnsafeAuthenticateConnectionSharing in the framework. Setting this value to true may affect performance.|
|Live ID Partner||Specifies a custom Live ID Partner URL that will override the default http://crm.dynamics.com|
The following example shows the connection string using integrated authentication:
The following example shows the connection string using Active Directory authentication:
Authentication Type=AD; Server=http://crm-server-name:port/crm-organization-name; User ID=user-domain\user-name; Password=user-password
The following example shows the connection string for an Internet-facing deployment (IFD):
Authentication Type=SPLA; Server=http://crm-server-name/crm-organization-name; User ID=user-domain\user-name; Password=user-password
The following example shows the connection string using Windows Live ID to connect to Microsoft Dynamics CRM Online:
Authentication Type=Passport; Server=https://crm-organization-name.crm.dynamics.com/crm-organization-name; User ID=user-windows-live-id; Password=user-password; Device ID=user-defined-device-id; Device Password=user-defined-device-password