Code Monkey home page Code Monkey logo

yugabyte-simple-csharp-app's Introduction

Simple C# Application for YugabyteDB

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 Managed deployments. If you use a different type of deployment, then update the sample-app.cs file with proper connection parameters.

Prerequisites

  • .NET 6.0 SDK or later version.
  • Command line tool or your favourite IDE, such as Visual Studio Code.

Start YugabyteDB Managed Cluster

Clone Application Repository

Clone the repository and change dirs into it:

git clone https://github.com/yugabyte/yugabyte-simple-csharp-app && cd yugabyte-simple-csharp-app

Provide Cluster Connection Parameters

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 to SslMode.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 Managed dashboard:

image

Run the Application

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

Explore Application Logic

Congrats! You've successfully executed a simple C# app that works with YugabyteDB.

Now, explore the source code of sample-app.cs:

  1. connect function - establishes a connection with your cloud instance via the Npgsql driver.
  2. createDatabase function - creates a table and populates it with sample data.
  3. selectAccounts function - queries the data with SQL SELECT statements.
  4. transferMoneyBetweenAccounts function - updates records consistently with distributed transactions.

Questions or Issues?

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!

yugabyte-simple-csharp-app's People

Contributors

dmagda avatar ddhodge avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.