# Creating Connection

## Content



To establish a connection to a JSON data source the ADO.NET provider can be used through the [C1JsonConnection](/componentone/api/services/online-dataconnector/dotnet-standard-api/C1.AdoNet.Json/C1.AdoNet.Json.C1JsonConnection.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 [C1JsonConnectionStringBuilder](/componentone/api/services/online-dataconnector/dotnet-standard-api/C1.AdoNet.Json/C1.AdoNet.Json.C1JsonConnectionStringBuilder.html) class by specifying individual statements.
*   Constructed manually by writing the connection string directly.

### Connection string generation

The following code shows how a connection string can be configured by the **C1JsonConnectionStringBuilder** class and consumed by the **C1JSsonConnection** class to create a connection to JSON. Through that connection, the data source can be queried, updated etc.

```csharp
//JSON service uri
const string docUri = @"json_bookstore.json";
//configure connection string
C1JsonConnectionStringBuilder connectionStringBuilder = new C1JsonConnectionStringBuilder();
connectionStringBuilder.DataModel = "Document";
connectionStringBuilder.Uri = docUri;
connectionStringBuilder.JsonPath = "$.bookstore.books";
//Setup Connection
C1JsonConnection con = new C1JsonConnection(connectionStringBuilder.ConnectionString);
```

### Connection string literal

Alternatively, the connection string can be written directly as a string literal, like in the following code. (a similar approach can be implemented in other DataConnectors for ADO.NET provider).

```csharp
//Create connection string
static string documentConnectionString = $"Data Model=Document;Uri='json_bookstore.json';Json Path='$.bookstore.books'";
//Setup Connection
C1JsonConnection con = new C1JsonConnection(documentConnectionString);
```

### JSON Data Sources

The ADO.NET provider for JSON allows you to connect to local and https JSON resources. For connecting to these resources, you need to set the [Uri](/componentone/api/services/online-dataconnector/dotnet-standard-api/C1.AdoNet.Json/C1.AdoNet.Json.C1JsonConnectionStringBuilder.Uri.html) property to the JSON resource location in addition to the [DataModel](/componentone/api/services/online-dataconnector/dotnet-standard-api/C1.AdoNet.Json/C1.AdoNet.Json.C1JsonConnectionStringBuilder.DataModel.html) and [JsonPath](/componentone/api/services/online-dataconnector/dotnet-standard-api/C1.AdoNet.Json/C1.AdoNet.Json.C1JsonConnectionStringBuilder.JsonPath.html) properties which are necessary to connect to your data source.

### Connect to Local Files

To connect to a local file, you can create a connection string by setting the **Uri** property to JSON file in addition to the **DataModel** and **JsonPath** properties as shown in the following code:

```csharp
static string documentConnectionString = $"Data Model=Document;Uri='json_bookstore.json';Json Path='$.bookstore.books'";
```

### Connect to HTTP JSON Streams

To connect to HTTP JSON Streams, you can create a connection string by setting the **Uri** property to the HTTP or HTTPS URL of the JSON resource you want to access as a table in addition to the **DataModel** and **JsonPath** properties, as shown in the following code:

```csharp
static string documentConnectionString = $"Data Model=Document;Uri='https://raw.githubusercontent.com/sassy224/ZipFiles/master/json_bookstore.json';Json Path='$.bookstore.books'";
```