Microsoft Dynamics 365 is a platform with a suite of applications that cover various business aspects, including accounting, finance, sales, marketing, and so on. Because Dynamics 365 is a widely used data source for many business applications, reliable connectivity is a key factor in ensuring proper and stable application performance.

The connection string is a set of parameters that contains the information required to establish a successful connection to the database or another data source, such as the Dynamics 365 platform. This guide explains the key components of dotConnect for Dynamics 365 connection strings, their construction, and best practices for using them.

Dynamics 365 connection strings

The following code snippet describes how to create a new connection to a Dynamics 365 account. Make sure to replace the placeholders with the credentials from your Dynamics 365 account.

using Devart.Data.Dynamics;
...
string connectionString = "Authentication Type=RefreshTokenInteractive;License Key=**********;";

Main connection properties

The following table lists the valid parameter names used in Dynamics 365 connection strings.

Name Description
Authentication Type Authentication method to use. The supported types are RefreshToken, RefreshTokenInteractive, and UsernamePassword. For more information, refer to AuthenticationType
Server Login URL to Dynamics CRM service
User Id Dynamics CRM login account that is required for UsernamePassword authentication
Password Password for UsernamePassword authentication
Client Id One of the two OAuth 2.0 credentials obtained when the application is registered
Client Secret The second part of the two OAuth 2.0 credentials obtained when the OAuth 2.0 application is registered
Refresh Token OAuth 2.0 refresh token for the RefreshToken authentication
License Key License key that should be specified in the connection string

Additional connection properties

The table below lists additional parameter names 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 closed 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 Specifies 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 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 Determines whether the provider retrieves a DynamicsConnection object from the appropriate pool or creates a new one. The default value is true
Run Once Command Execute this command when the connection is opened the first time. It is not executed when the connection is taken from the pool
Proxy Host Hostname or IP address of the proxy server
Proxy Password Password for the proxy server account
Proxy Port Default value is 3128
Proxy User Proxy server account name

Conclusion

When developing C# and .NET applications that use Dynamics 365 as a data source, it is important to ensure a stable and reliable connection to that source. In this article, we described how to configure connection strings for your application in Visual Studio.

dotConnect for Dynamics 365 helps resolve data connectivity challenges. 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 with your actual workload.

Dereck Mushingairi

I'm a technical content writer who loves turning complex topics — think SQL, connectors, and backend chaos–into content that actually makes sense (and maybe even makes you smile). I write for devs, data folks, and curious minds who want less fluff and more clarity. When I'm not wrangling words, you'll find me dancing salsa, or hopping between cities.

Try the 30-day trial of the full product. No limits. No card required. Start free trial