# Connect with .NET and .NET Core

The SingleStore Connector for .NET and .NET Core is an ADO.NET data provider for SingleStore. It implements the following classes: `DbConnection`, `DbCommand`, `DbDataReader`, and `DbTransaction`. Refer to the [GitHub repository](https://github.com/memsql/SingleStoreNETConnector) and [SingleStoreConnector on NuGet](https://www.nuget.org/packages/SingleStoreConnector/) for more information.

This library is licensed under the MIT license.

## Prerequisites

Download and install the latest stable version of [.NET Core](https://dotnet.microsoft.com/en-us/download).

## Install SingleStoreConnector

To install the `SingleStoreConnector` in a new project, run the following command:

```shell
dotnet add package SingleStoreConnector
```

You can also install the `SingleStoreConnector` using the NuGet Package Manager in Visual Studio. Refer to [SingleStoreConnector](https://www.nuget.org/packages/SingleStoreConnector/) on NuGet for more information.

## Configure the Connection

You need a connection string to connect your SingleStore cluster to .NET. The connection string uses the following format:

```C#
host=<hostname_or_ip_address>;port=<port>;userid=<username>;password=<password>;database=<database_name>;
```

Here's a sample connection string:

```C#
host=localhost;port=3306;userid=s2user;password=pass23key;database=s2_dbtest;
```

Refer to [Connection String Options](https://mysqlconnector.net/connection-options/) for more options.&#x20;

## Example

The following example creates a new project in Visual Studio Code and performs CRUD operations in SingleStore using C#.

Create a SingleStore cluster. For this example, we'll use the following connection string:

```C#
"Server=localhost;port=3306;User ID=s2user;Password=tK_,mh&Hq-EnN;Database=dbtest"

```

In Visual Studio Code, open the terminal, and create a project template:

```shell
dotnet new console -o dbTestNet
cd dbTestNet
```

Install the required dependencies, for example `SingleStoreConnector`:

```shell
dotnet add package SingleStoreConnector
```

## Create Operation Example

Add the following code to the `Program.cs` file of your project:

```C#
using SingleStoreConnector;

var connStr = "Server=localhost;port=3306;User ID=s2user;Password=tK_,mh&Hq-EnN;Database=dbtest";
var connection = new SingleStoreConnection(connStr);
connection.Open();

using var command = new SingleStoreCommand("CREATE TABLE testID (ID INT PRIMARY KEY, Code VARCHAR(4));INSERT INTO testID values(1, 'SamK');INSERT INTO testID values(2, 'JoeR');INSERT INTO testID values(3, 'BriA');",connection);
using var reader = command.ExecuteReader();
connection.Close();
```

In the terminal, run the following command:

```shell
dotnet run
```

On the SingleStore command line, execute the following command to verify that the `testID` table is created:

```sql
DESC testID;

```

```output

+-------+------------+------+------+---------+-------+
| Field | Type       | Null | Key  | Default | Extra |
+-------+------------+------+------+---------+-------+
| id    | int(11)    | NO   | UNI  | NULL    |       |
| code  | varchar(4) | YES  |      | NULL    |       |
+-------+------------+------+------+---------+-------+

```

## Read Operation Example

Add the following code to the `Program.cs` file of your project:

```C#
using SingleStoreConnector;

var connStr = "Server=localhost;port=3306;User ID=s2user;Password=tK_,mh&Hq-EnN;Database=dbtest";
var connection = new SingleStoreConnection(connStr);
connection.Open();

using var command = new SingleStoreCommand("SELECT * FROM testID",connection);
using var reader = command.ExecuteReader();
while (reader.Read())
{ 
  Console.Write(reader.GetInt32(0));
  Console.Write(" ");
  Console.WriteLine(reader.GetString(1));
}
connection.Close();

```

In the terminal, run the following command:

```shell
dotnet run

```

```output

1 SamK
2 JoeR
3 BriA

```

## Update Operation Example

Add the following code to the `Program.cs` file of your project:

```C#
using SingleStoreConnector;

var connStr = "Server=localhost;port=3306;User ID=s2user;Password=tK_,mh&Hq-EnN;Database=dbtest";
var connection = new SingleStoreConnection(connStr);
connection.Open();

using var command = new SingleStoreCommand("UPDATE testID SET Code = 'BenW' WHERE ID =3;SELECT * FROM testID",connection);
using var reader = command.ExecuteReader();
while (reader.Read())
{ 
  Console.Write(reader.GetInt32(0));
  Console.Write(" ");
  Console.WriteLine(reader.GetString(1));
}
connection.Close();

```

In the terminal, run the following command:

```shell
dotnet run

```

```output

1 SamK
2 JoeR
3 BenW

```

## Delete Operation Example

Add the following code to the `Program.cs` file of your project:

```C#
using SingleStoreConnector;

var connStr = "Server=localhost;port=3306;User ID=s2user;Password=tK_,mh&Hq-EnN;Database=dbtest";
var connection = new SingleStoreConnection(connStr);
connection.Open();

using var command = new SingleStoreCommand("DELETE FROM testID WHERE ID = 3;SELECT * FROM testID;",connection);
using var reader = command.ExecuteReader();
while (reader.Read())
{ 
  Console.Write(reader.GetInt32(0));
  Console.Write(" ");
  Console.WriteLine(reader.GetString(1));
}
connection.Close();

```

In the terminal, run the following command:

```shell
dotnet run

```

```output

1 SamK
2 JoeR

```

## In this section

* [Connect using Entity Framework Core](https://docs.singlestore.com/db/v9.1/developer-resources/connect-with-application-development-tools/connect-with-net-and-net-core/connect-using-entity-framework-core.md)

***

Modified at: October 3, 2025

Source: [/db/v9.1/developer-resources/connect-with-application-development-tools/connect-with-net-and-net-core/](https://docs.singlestore.com/db/v9.1/developer-resources/connect-with-application-development-tools/connect-with-net-and-net-core/)

(An index of the documentation is available at /llms.txt)
