.NET Connection Strings for Dynamics 365
Microsoft Dynamics 365 is a platform with a suite of applications that cover all business aspects, including accounting, finance, sales, marketing, and so on. Dynamics 365 is a popular data source for many applications. Therefore, the connectivity is the key factor for the proper functioning of the application.
The connection string is a string that contains the information necessary to establish a successful connection to the database or another data source, such as Dynamics 365 platform. This guide will explain the key components of dotConnect for Dynamics 365 connection strings, their construction, and best usage practices.
Dynamics 365 connection strings
The below code snippet describes how to create a new connection or connect to an existing Dynamics 365 account dynamically. Make sure to replace the placeholders with your actual credentials for the Dynamics 365 account.
using Devart.Data.Dynamics; ... string Server = "https://your_company.crm4.dynamics.com"; string UserId = "user@test.com"; string Password = "testpassword"; string LicenseKey = "**********"; string connectionString = $"Server={server};User Id={userId};Password={password};LicenseKey={LicenseKey};";
Main connection properties
The following table lists the valid names for values within the Dynamics 365 connection strings.
Name | Description |
---|---|
Authentication Type | The authentication method to use. The supported types are RefreshToken and UsernamePassword. For more information, refer to AuthenticationType. |
Server | The login URL to Dynamics CRM service. |
User Id | The Dynamics CRM login account that is required for UserNamePassword authentication. |
Password | The password for UserNamePassword authentication. |
Client Id | One part of the OAuth 2.0 credentials pair obtained when the OAuth 2.0 application is registered in the Azure AD tenant. |
Client Secret | The second part of the OAuth 2.0 credentials pair obtained when the OAuth 2.0 application is registered in the Azure AD tenant. |
Refresh Token | OAuth 2.0 refresh token for the RefreshToken authentication. |
License Key | The license key that should be specified in the connection string. |
Additional connection properties
The table below provides the valid names for values used in Dynamics 365 connection strings.
Name | Description |
---|---|
NormalizeDbNames | Performs the normalization of database names. |
Connect Timeout / Connection Timeout | Time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error. The default value is 15. |
Default Command Timeout | Time (in seconds) to wait for execution of a command before terminating the attempt and generating an error. A value of 0 indicates no limit. |
Failover Retries | The number of retries to execute a command if it fails because of the exception. It indicates that the reason for the failure may be temporary. |
Local SQL Engine | Enables local SQL processing, allowing more standard SELECT statement features. |
Readonly | Determines whether the connection is read-only (allows only SELECT statements). |
Token Server | Specifies the file path for storing the refresh token between sessions. The parameter is automatically set during the web login and typically doesn’t require modification. If necessary, a custom path can be set instead of the default path. |
UserAgent | Sets the value of the User-agent HTTP header. |
UTC Dates | Indicates whether all datetime values retrieved from the data source are returned as UTC values or converted to local time. Also, it indicates whether date values specified on the application side (for example, in SQL statements) are considered UTC or local. The default value is false. |
Connection Lifetime | Compares the connection creation time with the current time when a connection is returned to the pool. The connection is destroyed if that time span (in seconds) exceeds the value specified by Connection Lifetime. The default value is 0 (connection always returns to the pool). |
Initialization Command | Specifies a data source-specific command that should be executed immediately after establishing the connection. |
Max Pool Size | The maximum number of connections allowed in the pool. Setting the Max Pool Size value of the ConnectionString can affect performance. The default value is 100. |
Min Pool Size | The default value is 0. |
Persist Security Info | Indicates if security-sensitive information, such as the password, is not returned as part of the connection if the connection is open or has ever been open. |
Pooling | Retrieves the DynamicsConnection object from the appropriate pool or creates and adds it to the appropriate pool. The default value is true. |
Run Once Command | A command to execute when the connection is opened the first time. Is not executed when the connection is taken from the pool. |
Proxy Host | The hostname or IP address of the proxy server. |
Proxy Password | The password for the proxy server account. |
Proxy Port | The default value is 3128. |
Proxy User | The proxy server account name. |
Conclusion
Whenever you develop applications with C# and .NET using Dynamics 365 as the data source, you need to ensure a stable, accurate, and smooth connection to that data source. In this article, we presented the connection script for your application in Visual Studio and the values used in the connection strings.
dotConnect for Dynamics 365 is a solution that resolves data connectivity challenges easily. This powerful ADO.NET-based data provider developed by Devart lets you connect directly without additional clients and handle data-related tasks using familiar ADO.NET technologies. You can download the fully functional free trial of dotConnect for Dynamics 365 and test it under the actual workload.