This application connects to your YugabyteDB instance via the
Npgsql driver for PostgreSQL and performs basic SQL operations. The instructions below are provided for YugabyteDB Aeon deployments.
If you use a different type of deployment, then update the sample-app.cs
file with proper connection parameters.
- .NET 6.0 SDK or later version.
- Command line tool or your favourite IDE, such as Visual Studio Code.
- Start YugabyteDB Aeon instance. You can use the free tier at no cost.
- Add an IP address of your machine/laptop to the IP allow list
Clone the repository and change dirs into it:
git clone https://github.com/YugabyteDB-Samples/yugabyte-simple-csharp-app.git && cd yugabyte-simple-csharp-app
Locate and define the following connection parameters in the sample-app.cs
file:
urlBuilder.Host
- the hostname of your instance.urlBuilder.Username
- the username for your instance.urlBuilder.Password
- the database password.urlBuilder.SslMode
- make sure it's set toSslMode.VerifyFull
.urlBuilder.RootCertificate
- a full path to your CA root cert (for example,/Users/dmagda/certificates/root.crt
).
Note, you can easily find all the settings on the YugabyteDB Aeon dashboard:
Build and run the application:
dotnet run
Upon successful execution, you will see output similar to the following:
>>>> Connecting to YugabyteDB!
>>>> Successfully connected to YugabyteDB!
>>>> Successfully created table DemoAccount.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 10000
name = John, age = 28, country = Canada, balance = 9000
>>>> Transferred 800 between accounts
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 9200
name = John, age = 28, country = Canada, balance = 9800
Congrats! You've successfully executed a simple C# app that works with YugabyteDB.
Now, explore the source code of sample-app.cs
:
connect
function - establishes a connection with your cloud instance via the Npgsql driver.createDatabase
function - creates a table and populates it with sample data.selectAccounts
function - queries the data with SQLSELECT
statements.transferMoneyBetweenAccounts
function - updates records consistently with distributed transactions.
Having issues running this application or want to learn more from Yugabyte experts?
Join our Slack channel,
or raise a question on StackOverflow and tag the question with yugabytedb
!