Start CockroachDB
Choose whether to run a temporary local cluster or a free CockroachDB cluster on CockroachDB Standard. The instructions below will adjust accordingly.- Use CockroachDB Standard
- Use a Local Cluster
Create a free trial cluster
- . If this is your first CockroachDB Cloud organization, it will be credited with $400 in to get you started.
- On the Get Started page, click Create cluster.
- On the Select a plan page, select Standard.
- On the Cloud & Regions page, select a cloud provider (GCP or AWS).
- In the Regions section, select a region for the cluster. Refer to for the regions where CockroachDB Standard clusters can be deployed. To create a multi-region cluster, click Add region and select additional regions.
- Click Next: Capacity.
- On the Capacity page, keep the at the default value of 2 vCPUs. Click Next: Finalize.
- On the Finalize page, name your cluster. If an active free trial is listed in the right pane, you will not need to add a payment method, though you will need to do this by the to maintain your organization’s clusters. Click Create cluster. Your cluster will be created in a few seconds and the Create SQL user dialog will display.
Set up your cluster connection
The Connection info dialog shows information about how to connect to your cluster.- Click the Choose your OS dropdown, and select the operating system of your local machine.
- Click the Connection string tab in the Connection info dialog.
- Open a new terminal on your local machine, and run the command provided in step 1 to download the CA certificate. This certificate is required by some clients connecting to CockroachDB Cloud.
- Copy the connection string provided in step 2 to a secure location.
The connection string is pre-populated with your username, password, cluster name, and other details. Your password, in particular, will be provided only once. Save it in a secure place (Cockroach Labs recommends a password manager) to connect to your cluster in the future. If you forget your password, you can reset it by going to the SQL Users page for the cluster, found at
https://cockroachlabs.cloud/cluster/<CLUSTER ID>/users.Create a .NET project
In your terminal, run the following commands:dotnet command creates a new app of type console. The -o parameter creates a directory named cockroachdb-test-app where your app will be stored and populates it with the required files. The cd cockroachdb-test-app command puts you into the newly created app directory.
Install the Npgsql driver
Install the latest version of the Npgsql driver into the .NET project using the built-in nuget package manager:Create a database
- Use CockroachDB Standard
- Use a Local Cluster
- If you haven’t already, .
-
Start the using the connection string you got from the CockroachDB Cloud Console:
-
In the SQL shell, create the
bankdatabase that your application will use: -
Exit the SQL shell:
Set the connection string
- macOS / Linux
- Windows
Set a
DATABASE_URL environment variable to your connection string.Run the C# code
Now that you have set up your project and created a database, in this section you will:Basic example
Get the code
Replace the contents of theProgram.cs file that was automatically generated in your cockroachdb-test-app directory with the code below:
Run the basic example
Compile and run the code:Transaction example (with retry logic)
Modify the code
Opencockroachdb-test-app/Program.cs again and replace the contents with the code shown below.
- Use a Local Cluster
- Use CockroachDB Standard

