Set up .NET Core 3.1 to use MariaDb database

Tips to use .NET Core 3.1 and MariaDB

To use a MariaDb database in combination with a .NET Core 3.1 Web Application and support database migrations requires a specific approach. Here are a few tips:

In Visual Studio 2019, create a Web Application project and accept the default settings.

If the Microsoft.EntityFrameworkCore package is not installed by default, use the following command line in the Package Manager Console window of Visual Studio 2019 to install the latest version:

PM>Install-Package Microsoft.EntityFrameworkCore

Use the Pomelo.EntityFrameworkCore.MySql database provider

Use this database provider, because currently (June 2020) the MySql.Data.EntityFrameworkCore data provider does not support .NET Core 3.1.

See dev.mysql.com to check if support has changed in the meantime.

To install the Pomelo.EntityFrameworkCore.MySql database provider, enter the following command in the Package Manager Console window of Visual Studio 2019:

PM>Install-Package Pomelo.EntityFrameworkCore.MySql

The github page is: https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql

Add the MySqlConnector as a package to your Visual Studio project.

The MySqlConnector reference must be added to your Visual Studio project if you connect to a MariaDB MySQL database and want to use .NET migrations for the database. Enter the following command in the Package Manager Console window:

PM>Install-Package MySqlConnector

The github page is: https://www.nuget.org/packages/MySqlConnector/

Connection String

Put the database connection string in the Appsettings.json file of your Visual Studio project. For example:

<server=localhost;user id=YourUserName;pwd=YourPassword;database=NameOfDatabase>

About MariaDB

MariaDb is developed by the same developers as MySQL. This database can be installed on various operating systems. Aside from .NET Framework and .NET Core, a variety of programming languages can connect to MariaDB.

Visit the homepage to see what services Schouten offers. This includes the creation of applications (web and standalone) that use a MariaDB database among others.

Applies to:

.NET Core 3.1, Web Application, MariaDb database

Created: 3/7/2020 - Last Update: 9/30/2020 - Views: 924