DataConnector
接続の作成
ADO.NET provider for Dynamics 365 Sales > 接続の作成

To establish a connection to Dynamics 365 sales data source, the ADO.NET Provider can be used through the C1D365SConnection class. This class requires a connection string to be provided as an argument, which can be created in either of the following ways:

Connection string generation.

The code example below shows how a connection string can be configured by the C1D365SConnectionStringBuilder class and consumed by the C1D365SConnection class to create a connection to the Dynamics 365 Sales server. Through that connection, the data source can be queried, updated etc.

C#
コードのコピー
var builder = new C1D365SConnectionStringBuilder();
builder.Url = urlDynamics;
builder.Username = username;
builder.Password = password;
builder.OAuthTokenEndpoint = tokenEnpoint;
builder.OAuthExtendProperties = extendProperties;
builder.OAuthClientId = clientID;

// 接続属性は文字列で参照できます。
builder["Max Page Size"] = 100;
builder["Use Cache"] = true;

// 接続文字列を渡す接続を作成します。
var con = new C1D365SConnection(builder.ConnectionString); 
Console.WriteLine("Connection Created using C1D365SConnectionStringBuilder Class:");
Console.WriteLine("Created Connection String is:\n" + builder.ConnectionString);
Console.ReadKey();

Connection string literal

Alternatively, the connection string can be written directly as a string literal, like in the code example below (a similar approach can be implemented in other DataConnectors for ADO.NET provider).

C#
コードのコピー
// 接続文字列全体。
string connstr = $@"Url = {urlDynamics}; Use Cache = true; Use Etag = true; OAuth Client Id = {clientID}; Username = {username}; Password = {password}; 
           OAuth Token Endpoint = {tokenEnpoint}; OAuth Extend Properties = {extendProperties}; Max Page Size = 100";

// 接続を設定します。
var con = new C1D365SConnection(connstr);

Note: Connection strings can be formed by using as connection keys the names of the corresponding properties of C1D365SConnectionStringBuilder, but with an added space character. For example, to set the property UseCache, the connection key should be written as Use Cache.