DataConnector | ComponentOne
ADO.NET provider for Dynamics 365 Sales / Creating Connection
In This Topic
    Creating Connection
    In This Topic

    To create a connection in ADO.NET Provider, you can use C1D365SConnection class which implements a connection string passed as an argument. Another way to connect with the data source is using the C1D365SConnectionStringBuilder class which builds and parses connection strings through program code.

    The C1D365SConnectionStringBuilder class can also be used to setup the connection strings to be implemented by the provider for connecting to the datasource.

    Below code example shows how C1D365SConnectionStringBuilder class can be used to configure the connection string for Dynamics 365 Sales and consumed by C1365SConnection class to create a connection to Dynamics 365 Sales server. You can query the data or request for modifications.

    C1D365SConnectionStringBuilder builder = new C1D365SConnectionStringBuilder();
    builder.Url = urlDynamics;
    builder.Username = username;
    builder.Password = password;
    builder.OAuthTokenEndpoint = tokenEnpoint;
    builder.OAuthExtendProperties = extendProperties;
    builder.OAuthClientId = clientID;
    //You can refer to connection keys using strings
    builder["Max Page Size"] = 100;
    builder["Use Cache"] = true;
    var con = new C1D365SConnection(builder.ConnectionString);//Creating Connection using connection string as parameter
    Console.WriteLine("Connection Created using C1D365SConnectionStringBuilder Class:");
    Console.WriteLine("Created Connection String is:\n" + builder.ConnectionString);
    Note: The properties of C1D365SConnectionStringBuilder class can be used to setup the connection keys when passed as connection strings. The connection key will be the corresponding property with added space character. For example, "UseCache" will be used as "Use Cache".