# Creating Connection

## Content



To establish a connection to Dynamics 365 sales data source, the ADO.NET Provider can be used through the [C1D365SConnection](/componentone/api/services/online-dataconnector/dotnet-standard-api/C1.AdoNet.D365S/C1.AdoNet.D365S.C1D365SConnection.html) class. This class requires a connection string to be provided as an argument, which can be created in either of the following ways:

*   Generated using the [C1D365SConnectionStringBuilder](/componentone/api/services/online-dataconnector/dotnet-standard-api/C1.AdoNet.D365S/C1.AdoNet.D365S.C1D365SConnectionStringBuilder.html) class by specifying individual statements.
*   Constructed manually by writing the connection string directly.

### 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.

```csharp
var builder = new C1D365SConnectionStringBuilder();
builder.Url = urlDynamics;
builder.Username = username;
builder.Password = password;
builder.OAuthTokenEndpoint = tokenEnpoint;
builder.OAuthExtendProperties = extendProperties;
builder.OAuthClientId = clientID;
// Connection attributes can be referred to by string
builder["Max Page Size"] = 100;
builder["Use Cache"] = true;
// Create Connection passing connection string
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).

```csharp
// Whole 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";
// Setup the connection
var con = new C1D365SConnection(connstr);
```


> type=note
> **Note**: Connection strings can be formed by using as connection keys the names of the corresponding properties of [C1D365SConnectionStringBuilder](/componentone/api/services/online-dataconnector/dotnet-standard-api/C1.AdoNet.D365S/C1.AdoNet.D365S.C1D365SConnectionStringBuilder.html) but with an added space character. For example, to set the property UseCache, the connection key should be written as UseCache.