DataConnector
ADO.NET provider for Dynamics 365 Sales / Getting Started
In This Topic
    Getting Started
    In This Topic

    DataConnector offers everything from wide range of data connection techniques using ADO.NET provider for Dynamics 365 Sales. This documentation helps you get started with C1.DataConnector control which gives an idea about different ways of data connection and operations with Dynamics 365 Sales.

    This quick start will guide you through the steps of using DataConnector in a console application. Complete the steps given below to see how DataConnector works.

    Step 1: Create a new Console App

    1. Open Visual Studio
    2. Select File -> New -> Project.
    3. In the center pane, select Console App (.Net Core).
    4. Add a name for your app and select a location to save it.
    5. Click OK.
          Consolde App

    Step 2: Add the NuGet packages

    1. From the Project menu, select Manage NuGet Packages. The NuGet Package Manager appears.
    2. Select nuget.org from the Package source drop down.
    3. Click Browse tab and select C1.AdoNet.D365S from the left pane.
    4. In the right pane, click Install. This adds the references for the above packages.

    Step 3: Using ADO.NET provider for Dynamics 365 Sales

    Follow the steps provided below to learn and implement data retrieval using ADO.NET provider for Dynamics 365 Sales.

    1.  The first step is to create a reference to Dynamic365 Sales service URLs and connection properties.
      const string urlDynamics = @https://xxx.xxx.xxx.xxx.com/api/data/v9.1/;
      const string ClientSecret = ""
      const string clientID = "";
      const string username = "";
      const string password = "";
      const string tokenEnpoint = @"https://login.microsoftonline.com/common/oauth2/token";
      const string extendProperties = @"{""resource"":""https://xxx.xxx.xxx.com/""}";
      
    2. In the below code exampleC1D365SConnection is used to retrieve the data. The connection string using corresponding attributes is passed as an argument. The example implements OAuth protocol for authorization. DbDataReader objects retrieve data in subset increments as required. Click here for more information on creating connections.
      //Password credential in connection string
      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";
      using (var con = new C1D365SConnection(connstr))//Creating Connection using connection string as parameter
      {
        //Open connection
        con.Open();
        //Create Command
        var cmd = con.CreateCommand();
        cmd.CommandText = "Select  accountid, name  FROM Accounts limit 10'";
        //Executing Reader
        DbDataReader rdr = cmd.ExecuteReader();
        //Dispalaying Data using Reader Object
        while (rdr.Read())
        {
          Console.WriteLine(String.Format("\t{0} --> \t\t{1}", rdr["accountid"], rdr["name"]));
        }
      }
      

    The following output is generated on the console application after executing the above steps.

    Output