Skip to content

C# Connection

MatrixOne Intelligence supports C# connections and supports MySQL Connector/NET drivers.

This document will guide you through how to connect to MatrixOn Intelligence using C#.

Prepare before starting

Connecting MO Intelligence instances using C

Step 1: Create a C# application

Use the dotnet command to create a new console application. For example, create a new app called myapp:

dotnet new console -o myapp

Then switch to the myapp directory

Step 2: Add the MySQL Connector/NET NuGet package

Install the MySql.Data package using the NuGet package manager:

dotnet add package MySql.Data

Step 3: Connect to MO Intelligence instance

Write the following code in the Program.cs file:

using System;
using MySql.Data.MySqlClient;

class Program
{
    static void Main(string[] args)
    {
        Program n = new Program();
        string connectionString = "server=freetier-01.cn-hangzhou.cluster.matrixonecloud.cn;user=585b49fc_852b_4bd1_b6d1_d64bc1d8xxxx:admin:accountadmin;database=test;port=6001;password=xxx";
        using (MySqlConnection connection = new MySqlConnection(connectionString))
        {
            try{
            connection.Open();
            Console.WriteLine("Connection established successfully");
            }
            catch (MySqlException ex)
            {
                Console.WriteLine(ex.Message);
            }
            Finally
            {
                connection.Close();
            }
        }
    }
}

Step 4: Run the program

Execute the command dotnet run in the terminal:

(base) admin@admindeMacBook-Pro myapp % dotnet run
Connection successfully established

Reference Document

For an example of using C# to build a simple CRUD with MatrixOne, see C# Basic Example.