DataConnector | ComponentOne
In This Topic
    DbFactory Support
    In This Topic

    DataConnector supports DbProvider Factories which enables the data connectors to be used by applications and tools that allow external ADO.NET data connectors to be used via these DbProvider Factory configurations. Let us take an example of Salesforce to understand how the DataConnector supports DbProvider Factories. The ADO.NET Provider for Salesforce implements the C1SalesforceProviderFactory class to provide support for DbProviderFactory and allow you to write generic data access code to Salesforce through the ADO.NET base classes.

    The following sections demonstrate how you can create Data Access Objects with C1SalesforceProviderFactory. To connect to SalesForce with generic code, you can use DbProviderFactory and DbConnection objects.

    Register the Provider to the Configuration Context

    Register the ADO.NET provider for SalesForce manually in the configuration context (app.config, or web.config) of DbFactory configuration in a Windows application to create a strongly typed DbProviderFactory using the following code:

    App.config
    Copy Code
    <system.data>
        <DbProviderFactories>
            <add name="C1.AdoNet.Salesforce" invariant="C1.AdoNet.Salesforce" 
                    description="C1.AdoNet.Salesforce is a data provider that allow 
                    to work with Salesforce service via ADO.NET APIs."
                    type="C1.AdoNet.Salesforce.C1SalesforceProviderFactory, 
                    C1.AdoNet.Salesforce, Version=1.0.20***.**, Culture=neutral, 
                    PublicKeyToken=yourToken"   />
         </DbProviderFactories>
    </system.data>
    

    The following fragment in the configuration file demonstrates a Salesforce connection string in the context:

    App.config
    Copy Code
    <connectionStrings>
    <add name="SalesforceServer" providerName="C1.AdoNet.Salesforce" 
               connectionString="Username=***@****.com;Password=******;
               Security Token=yourToken;OAuth Client Id=yourID;
               OAuth Client Secret=yourClientSecret;
               OAuth Token Endpoint=yourToken;
               Url=yourURL; Use Pool = false; Max Page Size = 200" />
    </connectionStrings>
    

    Define the DbProviderFactory and the DbConnection Objects

    Create a strongly typed DbProviderFactory object, use it to instantiate a DbConnection object and connect to Salesforce using the following code.

    C#
    Copy Code
    DbProviderFactory factory = DbProviderFactories.GetFactory("C1.AdoNet.Salesforce");
    
    //Create connection
    using (DbConnection connection = factory.CreateConnection())
    {
          connection.ConnectionString = "User=yourUser;Password=yourPassword;Security Token=yourToken;";
          connection.Open();
    }
    

    On the contrary, you can also read the connection string from the config file of the application. Note that the ConnectionStringSettingsCollection class requires a reference to System.Configuration.dll.

    To retrieve the Salesforce connection string defined in the application config file, use the following code.

    C#
    Copy Code
    ConnectionStringSettingsCollection csettings = ConfigurationManager.ConnectionStrings;
    
    //Setting connection string, by fetching it from configuration file
    if (csettings != null)
    {
        foreach (ConnectionStringSettings connString in csettings)
        {
             if (connString.ProviderName == "C1.AdoNet.Salesforce")
             {
                 connection.ConnectionString = connString.ConnectionString;
                 break;
             }
        }
    }
    

    Execute DbCommands

    Fetch the database information using the DbProviderFactory and DbConnection objects to execute queries to Salesforce. In the following code, we execute a "SELECT *" query to Salesforce with an existing DbConnection object.

    C#
    Copy Code
    //Create command
    DbCommand command = factory.CreateCommand();
    command.Connection = connection;
    command.CommandText = "Select * from Customer__c limit 5";
    
    //Create DataAdapter
    DbDataAdapter adapter = factory.CreateDataAdapter();
    adapter.SelectCommand = command;
    
    //Fill DataTable
    DataTable dataTable = new DataTable();
    adapter.Fill(dataTable);
    
    //Bind DataTable to C1FlexGrid
    c1FlexGrid1.DataSource = dataTable;
    

    Similarly, you can register the other supported ADO.NET Providers in context of DbFactory configuration on the local App.config files using the required information from the following table:

    Provider Name Provider Registration String Connection String
    OData
    <system.data>
      <DbProviderFactories>
        <add name="C1.AdoNet.OData"
           invariant="C1.AdoNet.OData"
           description="ADO.NET provider for OData service"
           type="C1.AdoNet.OData.C1ODataProviderFactory, 
           C1.AdoNet.OData, Version=1.0.20***.**,
           Culture=neutral, PublicKeyToken=yourToken" />
      </DbProviderFactories>
    </system.data>
    
    <connectionStrings>
      <add name="ODataServer"
         providerName="C1.AdoNet.OData" 
         connectionString="Url=https://***/***/***;
         Password=******;Username=***@****.com;
         Use Dynamic Type = 'false'" />
      </connectionStrings>
    
    Dynamic 365 Sales
    <system.data>
      <DbProviderFactories>
        <add name="C1.AdoNet.D365S" 
           invariant="C1.AdoNet.D365S"
           description="ADO.NET provider for D365S service."
           type="C1.AdoNet.D365S.C1D365SProviderFactory,
           C1.AdoNet.D365S, Version=1.0.20***.**, 
           Culture=neutral, PublicKeyToken=yourToken" />
      </DbProviderFactories>
    </system.data>
    
    
    <connectionStrings>
      <add name="D365SServer" 
       providerName="C1.AdoNet.D365S" 
       connectionString="Url=https://***/***/***;
       OAuth Client Id=***********;
       OAuth Client Secret=********;
       OAuth Token Endpoint=https://***/***/***;
       OAuth Extend Properties=yourExtendProperties;
       Use Etag=true;Max Page Size = 100" />
    </connectionStrings>
    
    Kintone
    <system.data>
      <DbProviderFactories>
        <add name="C1.AdoNet.Kintone" 
           invariant="C1.AdoNet.Kintone"
           description="ADO.NET provider for Kintone service."
           type="C1.AdoNet.Kintone.C1KintoneProviderFactory,
           C1.AdoNet.Kintone, Version=1.0.20***.**,
           Culture=neutral, PublicKeyToken=yourToken" />
      </DbProviderFactories>
    </system.data>
    
    <connectionStrings>
      <add name="KintoneServer" 
        providerName="C1.AdoNet.Kintone" 
        connectionString="Url=https://***/***/***;
        Username=***@****.com;Password=******;" />
    </connectionStrings>
    
    QuickBooks Online
    <system.data>
      <DbProviderFactories>
        <add name="C1.AdoNet.QuickBooksOnline" 
           invariant="C1.AdoNet.QuickBooksOnline"
           description="ADO.NET provider for QuickBooksOnline service"
           type="C1.AdoNet.QuickBooksOnline.C1QuickBooksOnlineProviderFactory,
           C1.AdoNet.QuickBooksOnline, Version=1.0.20***.**,
           Culture=neutral, PublicKeyToken=yourToken" />
      </DbProviderFactories>
    </system.data>
    
    <connectionStrings>
      <add name="QuickBooksOnlineServer" 
        providerName="C1.AdoNet.QuickBooksOnline" 
        connectionString="Company Id=yourID;
        OAuth Access Token=yourToken;
        OAuth Client Id=***********;
        OAuth Client Secret=********;
        OAuth Refresh Token=*******;
        OAuth Token Endpoint=https://***/***/***;
        Minor Version=14; Use Pool=false; 
        Max Page Size = 50;Country Code=yourCode;
        Use SandBox=True" />
    </connectionStrings>
    
    Google Analytics
    <system.data>
      <DbProviderFactories>
        <add name="C1.AdoNet.GoogleAnalytics"
           invariant="C1.AdoNet.GoogleAnalytics"
           description="ADO.NET provider for GoogleAnalytics service"
           type="C1.AdoNet.GoogleAnalytics.C1GoogleAnalyticsProviderFactory,
           C1.AdoNet.GoogleAnalytics, Version=1.0.20***.**, 
           Culture=neutral, PublicKeyToken=yourToken" />
      </DbProviderFactories>
    </system.data>
    
    <connectionStrings>
      <add name="GoogleAnalyticsServer"
        providerName="C1.AdoNet.GoogleAnalytics" 
        connectionString="Key File=yourFile;
        View Id=*******" />
    </connectionStrings>