DataConnector
ADO.NET provider for Salesforce / Creating Connection
In This Topic
    Creating Connection
    In This Topic

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

    The C1SalesforceConnectionStringBuilder 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 C1SalesforceConnectionStringBuilder class can be used to configure the connection string for Salesforce and consumed by C1SalesforceConnection class to create a connection to Salesforce server. You can query the data or request for modifications.

    CS
    Copy Code
    //Salesforce service URL
    const string GCSalesforceServerConnectionString = @"Username=**********;Password=***********;Security Token=************;
                                                    OAuth Client Id=***********; 
                                                    OAuth Client Secret=***************; 
                                                    OAuth Token Endpoint=https://ap16.salesforce.com/services/oauth2/token; 
                                                    Url=https://ap16.salesforce.com/services/data/v45.0";
    // Configure connection string            
    C1SalesforceConnectionStringBuilder builder = new C1SalesforceConnectionStringBuilder();
    builder.ConnectionString = $@"{GCSalesforceServerConnectionString}";
    
    //Setup Connection
    C1SalesforceConnection con = new C1SalesforceConnection(builder.ConnectionString);
    

    In Salesforce, ApiVersion (“API Version”) property in connection string specifies the API version of Salesforce to be used. You can specify the ApiVersion in following ways:

    The lowest api version we support is 42. Setting value lower than this will throw exception.

    Note: The properties of C1SalesforceConnectionStringBuilder 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".