Save Big on Cyber Monday! Up to 40% Off
ends in   {{days}}
Days
{{timeFormat.hours}}
:
{{timeFormat.minutes}}
:
{{timeFormat.seconds}}

Getting Started With dotConnect for MySQL

Below are some resources to help you maximize your experience with dotConnect for MySQL.

dotConnect for MySQL is a high-performance ADO.NET data provider with ORM support, offering fast and direct access to MySQL and MariaDB for application development.

  • EF Core, Dapper, NHibernate, LinqConnect, and other ORMs support
  • SSL, SSH, proxy servers, and HTTP tunnels support
  • Broad compatibility with various .NET platforms and versions
  • Full compliance with ADO.NET
  • Integration with Visual Studio

Code examples

using Devart.Data.MySql;

class Program
{
  static void Main()
  {
  string connectionString = "" +
  "Server=127.0.0.1;" +
  "Port=3306;" +
  "UserId=TestUser;" +
  "Password=TestPassword;" +
  "Database=sakila;" +
  "LicenseKey=**********";

  using (MySqlConnection connection = new MySqlConnection(connectionString))
  {
    try
    {
      connection.Open();
      Console.WriteLine("Connection successful!");
    }
    catch (Exception ex)
    {
      Console.WriteLine($"Error: {ex.Message}");
    }
  }
  }
}
PM> Install-Package Devart.Data.MySql
using Devart.Data.MySql;

class Program
{
  static void Main()
  {
    // Define your connection string with SSL options
    MySqlConnection connection = new MySqlConnection(
      "Server=127.0.0.1;" +
      "Protocol=SSL;" +
      "UserId=TestUser;" +
      "Password=TestPassword;" +
      "Database=sakila;" +
      "LicenseKey=**********"
    );

    // Set SSL options
    connection.SslOptions.CACert = "file://D:\\Project\\CA-cert.pem";
    connection.SslOptions.Cert = "file://D:\\Project\\SSL-client-cert.pem";
    connection.SslOptions.Key = "file://D:\\Project\\SSL-client-key.pem";

    try
    {
      connection.Open();
      Console.WriteLine("SSL connection to the database opened successfully!");

      // Perform database operations here
      // For example, execute a simple query
      string query = "SELECT DATABASE();";
      using (MySqlCommand command = new MySqlCommand(query, connection))
      {
        object result = command.ExecuteScalar();
        Console.WriteLine($"Connected to database: {result}");
      }
    }
    catch (Exception ex)
    {
      Console.WriteLine($"Error: {ex.Message}");
    }
  }
}
PM> Install-Package Devart.Data.MySql
using Devart.Data.MySql;

class Program
{
  static void Main()
  {
    string connectionString =
      "Server=127.0.0.1;" +
      "Port=3306;" +
      "UserId=TestUser;" +
      "Password=TestPassword;" +
      "Database=sakila;" +
      "LicenseKey=**********";

    using (MySqlConnection connection = new MySqlConnection(connectionString))
    {
      try
      {
        connection.Open();
        Console.WriteLine("Connection successful!");

        // Define a query to select data from the actor table
        string query = "SELECT actor_id, first_name, last_name FROM actor";

        // Create a command object
        using (MySqlCommand command = new MySqlCommand(query, connection))
        {
          // Execute the query and get a data reader
          using (MySqlDataReader reader = command.ExecuteReader())
          {
            // Loop through the result set
            while (reader.Read())
            {
              // Access the data using column names or indices
              int actorId = reader.GetInt32("actor_id");
              string firstName = reader.GetString("first_name");
              string lastName = reader.GetString("last_name");

              // Print the data to the console
              Console.WriteLine($"Actor ID: {actorId}, Name: {firstName} {lastName}");
            }
          }
        }
      }
      catch (Exception ex)
      {
        Console.WriteLine($"Error: {ex.Message}");
      }
    }
  }
}
PM> Install-Package Devart.Data.MySql
using Microsoft.EntityFrameworkCore;
using Devart.Data.MySql.EFCore;

public class Actor
{
  public int ActorId { get; set; }
  public string FirstName { get; set; }
  public string LastName { get; set; }
}

public class SakilaContext : DbContext
{
  public DbSet<Actor> Actors { get; set; }

  protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  {
    optionsBuilder.UseMySql(
      "Server=127.0.0.1;Port=3306;UserId=TestUser;Password=TestPassword;Database=sakila;LicenseKey=**********",
      MySqlServerVersion.LatestSupportedServerVersion
    );
  }
}

class Program
{
  static void Main()
  {
    using (var context = new SakilaContext())
    {
      try
      {
        // Ensure the database is created
        context.Database.EnsureCreated();
        Console.WriteLine("Connected to the database successfully!");

        // Query data from the Actors table
        var actors = context.Actors;
        foreach (var actor in actors)
        {
          Console.WriteLine($"Actor ID: {actor.ActorId}, Name: {actor.FirstName} {actor.LastName}");
        }
      }
      catch (Exception ex)
      {
        Console.WriteLine($"Error: {ex.Message}");
      }
    }
  }
}
PM> Install-Package Devart.Data.MySql.EFCore
using Devart.Data.MySql;

class Program
{
  static void Main()
  {
    string connectionString =
      "Server=127.0.0.1;" +
      "Port=3306;" +
      "UserId=TestUser;" +
      "Password=TestPassword;" +
      "Database=sakila;" +
      "LicenseKey=**********";

    using (MySqlConnection connection = new MySqlConnection(connectionString))
    {
      try
      {
        connection.Open();
        Console.WriteLine("Connection successful!");

        // Define a query to select data from the actor table
        string query = "SELECT actor_id, first_name, last_name FROM actor";

        // Create a command object
        using (MySqlCommand command = new MySqlCommand(query, connection))
        {
          // Create a data adapter
          using (MySqlDataAdapter adapter = new MySqlDataAdapter(command))
          {
            // Create a DataTable to hold the data
            DataTable dataTable = new DataTable();

            // Fill the DataTable with data from the database
            adapter.Fill(dataTable);

            // Loop through the DataTable and print the data
            foreach (DataRow row in dataTable.Rows)
            {
              int actorId = (int)row["actor_id"];
              string firstName = row["first_name"].ToString();
              string lastName = row["last_name"].ToString();

              Console.WriteLine($"Actor ID: {actorId}, Name: {firstName} {lastName}");
            }
          }
        }
      }
      catch (Exception ex)
      {
        Console.WriteLine($"Error: {ex.Message}");
      }
    }
  }
}
PM > Install-Package Devart.Data.MySql
using Devart.Data.MySql;

class Program
{
  static void Main()
  {
    string connectionString =
      "Server=127.0.0.1;" +
      "Port=3306;" +
      "UserId=TestUser;" +
      "Password=TestPassword;" +
      "Database=sakila;" +
      "LicenseKey=**********";

    using (MySqlConnection connection = new MySqlConnection(connectionString))
    {
      try
      {
        connection.Open();
        Console.WriteLine("Connection successful!");

        // Start a transaction
        using (MySqlTransaction transaction = connection.BeginTransaction())
        {
          try
          {
            // Create a command to insert a new actor
            string insertQuery = "INSERT INTO actor (first_name, last_name) VALUES ('John', 'Doe')";
            using (MySqlCommand insertCommand = new MySqlCommand(insertQuery, connection, transaction))
            {
              insertCommand.ExecuteNonQuery();
              Console.WriteLine("Insert command executed.");
            }

            // Create a command to update an existing actor
            string updateQuery = "UPDATE actor SET last_name = 'Smith' WHERE first_name = 'John' AND last_name = 'Doe'";
            using (MySqlCommand updateCommand = new MySqlCommand(updateQuery, connection, transaction))
            {
              updateCommand.ExecuteNonQuery();
              Console.WriteLine("Update command executed.");
            }

            // Commit the transaction
            transaction.Commit();
            Console.WriteLine("Transaction committed successfully.");
          }
          catch (Exception ex)
          {
            // Roll back the transaction if any command fails
            transaction.Rollback();
            Console.WriteLine($"Transaction rolled back due to an error: {ex.Message}");
          }
        }
      }
      catch (Exception ex)
      {
        Console.WriteLine($"Error: {ex.Message}");
      }
    }
  }
}
PM> Install-Package Devart.Data.MySql
using Devart.Data.MySql;

class Program
{
  static void Main()
  {
    string connectionString =
      "Server=127.0.0.1;" +
      "Port=3306;" +
      "UserId=TestUser;" +
      "Password=TestPassword;" +
      "Database=sakila;" +
      "LicenseKey=**********";

    using (MySqlConnection connection = new MySqlConnection(connectionString))
    {
      try
      {
        connection.Open();
        Console.WriteLine("Connection successful!");

        // Attempt to execute a query that may cause an exception
        string query = "SELECT * FROM non_existent_table";
        using (MySqlCommand command = new MySqlCommand(query, connection))
        {
          using (MySqlDataReader reader = command.ExecuteReader())
          {
            while (reader.Read())
            {
              // Process data (this won't be reached if the table doesn't exist)
              Console.WriteLine(reader["column_name"]);
            }
          }
        }
      }
      catch (MySqlException ex)
      {
        // Handle MySqlException and display error details
        Console.WriteLine($"MySQL Error: {ex.Message}");
        Console.WriteLine($"Error Code: {ex.Code}");
        Console.WriteLine($"Error Source: {ex.Source}");
        Console.WriteLine($"Stack Trace: {ex.StackTrace}");
      }
      catch (Exception ex)
      {
        // Handle any other exceptions
        Console.WriteLine($"General Error: {ex.Message}");
      }
    }
  }
}
PM> Install-Package Devart.Data.MySql

Demo videos

How-to articles

.NET MySQL Connection Strings
Learn how to set up connection strings properly when working with dotConnect for MySQL in .NET applications.
Connect to MySQL in .NET
Explore how to establish a connection between .NET applications and MySQL or MariaDB using ADO.NET.
Connect to MySQL with EF Core
Find out how to connect MySQL and MariaDB databases to your application using EF Core and ADO.NET.
Connect to MySQL in Blazor
Learn how to integrate MySQL or MariaDB with .NET Blazor applications using EF Core and ADO.NET.
Connect to MySQL in MAUI
See how to build .NET MAUI applications and perform CRUD operations with MySQL and MariaDB using ADO.NET.
Connect to MySQL with Dapper
Learn how to connect C# to MySQL using Dapper for fast and efficient data access.

Documentation

Licensing
Licensing
A detailed technical reference on embedding license information - a required resource for applications built with dotConnect for MySQL.
DataTable Features
DataTable features
A guide to using the MySqlDataTable component and its features, like server connections, command objects, data storage, and data access.
Parameters
Parameters
An overview of SQL query parameters and their synchronization, along with practical insights into working with stored procedures.
Specific Features
Specific features
An explanation of support for MySQL-specific technologies, including secure connections, embedded servers, load balancing, and more.

dotConnect Universal

Get universal access to data from a variety of sources, including SQL Server, Oracle, PostgreSQL, MySQL, SQLite, DB2, InterBase, Microsoft Access, and Firebird. Other servers can be accessed through their ADO.NET, OLE DB and ODBC providers.

FAQ

What is the trial period for dotConnect for MySQL?
dotConnect for MySQL offers a fully functional 30-day trial. During this period, you can use and evaluate all features without limitations. After the trial ends, you can purchase a license to keep using the product.
Why do I need to install the product if NuGet is available?

dotConnect for MySQL provides two sets of assemblies, and the choice depends on your project type:

  • For .NET Framework projects: Use the Devart assemblies included with the product installer.
  • For .NET (.NET Core/.NET 5+) projects: Use the assemblies available via NuGet packages.
Where should I apply my License Key?

The method for applying your license depends on your project type:

  • For .NET (.NET Core/.NET 5+) projects, apply the License Key at runtime using the License Key connection string parameter.
  • For .NET Framework projects, no license key is needed. Simply download and install the licensed version of dotConnect from your Devart Customer Portal.
What editions of dotConnect for MySQL are available, and what's the difference?

There are five editions:

  • Express - Free version with basic connectivity.
  • Standard - Full ADO.NET provider with design-time support.
  • Professional - Adds ORM tools like Entity Framework and LinqConnect.
  • Developer - Includes all Professional features.
  • Mobile - Provides Standard features for the .NET Compact Framework.
Do end users of my application need a Devart license, or do I have to pay additional fees for deploying my software?

No, end users do not need a Devart license, and there are no additional deployment fees, as long as you hold a valid Devart license.

According to the EULA, you're allowed to redistribute the following runtime assemblies with your application:

  • Devart.Data.MySql.dll
  • Devart.Data.dll

You can include them in your app's folder (such as Bin for web apps) or register them in the GAC. Just make sure they are only used by your solution.

There's no need for a full installation on the target machine, you can also use the "Minimal installation" option provided by the setup.

No other components of dotConnect may be distributed.

How can I update dotConnect to a new version?

To update dotConnect to a new version, you need to reinstall it:

  • 1. Open Settings > Apps > Installed apps in Windows.
  • 2. Uninstall the current and any older versions of dotConnect, including Entity Developer and LinqConnect, if installed.
  • 3. Visit the Customer Portal and download the latest licensed version.
  • 4. Install the downloaded version and receive the latest features and improvements.
How can I completely remove all previous versions of a product?

1. Go to Settings > Apps > Installed apps and uninstall:

  • All dotConnect providers
  • Entity Developer
  • LinqConnect

2. Manually delete any leftover files from the following locations (if they exist):

GAC folders:

  • C:\Windows\assembly\GAC_MSIL
  • C:\Windows\Microsoft.NET\assembly\GAC_MSIL

Program files and extensions:

  • C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\Devart
  • C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Devart
  • C:\Program Files (x86)\Devart
  • C:\Program Files\Devart
  • C:\Program Files (x86)\Common Files\Devart
  • C:\Program Files\Common Files\Devart

Program data folders:

  • C:\ProgramData\Devart\dotConnect
  • C:\ProgramData\Devart\Entity Developer
  • C:\ProgramData\Devart\EntityDeveloper

Removing these ensures a clean system and prevents conflicts during future installations.

Wield the full firepower of dotConnect for MySQL
Go with the advanced edition of dotConnect for MySQL and stay at the top of your game from day one!