# Creating Connection

## Content



To create a connection to QuickBooks Online, the ADO.NET Provider can be used through the [C1QuickBooksOnlineConnection](/componentone/api/services/online-dataconnector/dotnet-standard-api/C1.AdoNet.QuickBooksOnline/C1.AdoNet.QuickBooksOnline.C1QuickBooksOnlineConnection.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 [C1QuickBooksOnlineConnectionStringBuilder](/componentone/api/services/online-dataconnector/dotnet-standard-api/C1.AdoNet.QuickBooksOnline/C1.AdoNet.QuickBooksOnline.C1QuickBooksOnlineConnectionStringBuilder.html) class by specifying individual statements.
*   Constructed manually by writing the connection string directly.

The following code shows how the **C1QuickBooksOnlineConnectionStringBuilder** class can be used to configure the connection string for QuickBooks Online and consumed by the **C1QuickBooksOnlineConnection** class to create a connection to QuickBooks Online server. Here you can query the data or request modifications.

```csharp
static void CreatingConn()
{           
    //Configure Connection string
    C1QuickBooksOnlineConnectionStringBuilder builder = new C1QuickBooksOnlineConnectionStringBuilder
    {
        OAuthClientId = OAuthClientId,
        OAuthClientSecret = OAuthClientSecret,
        OAuthTokenEndpoint = OAuthTokenEndpoint,
        OAuthAccessToken = OAuthAccessToken,
        OAuthRefreshToken = OAuthRefreshToken,
        CompanyId = CompanyId,
        UseSandbox = true
    };
    //Setup Connection
    using (C1QuickBooksOnlineConnection conn = new C1QuickBooksOnlineConnection(builder.ConnectionString))
    {
        conn.OAuthTokenRefreshed += OAuthTokenRefreshed;
        //Tried fetching data from two different tables
        C1QuickBooksOnlineCommand comm = new C1QuickBooksOnlineCommand(conn, "Select * from Customers");
        C1QuickBooksOnlineDataAdapter adapter = new C1QuickBooksOnlineDataAdapter(comm);
        DataTable dataTable = new DataTable();
        adapter.Fill(dataTable);
        //Display fetched data
        foreach (DataRow row in dataTable.Rows)
        {
            Console.WriteLine("{0}\t{1}\t{2}", row["CompanyName"], row["DisplayName"], row["Active"]);
        }
        Console.WriteLine("Connection created and read operation completed !!!");
    }
}
```