Csaba
Csaba

Reputation: 351

SQLConnection to MariaDB localhost via .NetCore

I'm playing with .NetCore 3.0 Entity Framework on my Ubuntu Linux. I have MariaDB installed, user Joe added to access MariaDB. I'm able to access the DB using:

mysql -u Joe -p -h localhost

I have the following code in .Net:

using Microsoft.EntityFrameworkCore;

public class MyDbContext : DbContext
{
   public DbSet<TestModel> TestModels { get; set; }

   protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
   {
      optionsBuilder.UseSqlServer(
          @"Server=localhost; Database=MyTestDb; User Id=Joe; Password=abc;");
   }
}

The project has both NuGet packages imported:

Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.SqlServer

When I try to run this code or "migrate/update" the database using dotnet ef database update I receive the following exception:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server)

I even enabled remote connection access to MariaDB, although I'm accessing it from the given computer where the DB is located.

Thanks for any advice :-)

Upvotes: 1

Views: 2210

Answers (1)

Bradley Grainger
Bradley Grainger

Reputation: 28207

Microsoft.EntityFrameworkCore.SqlServer is the package for Microsoft SQL Server. The EF Core package for MySQL/MariaDB is Pomelo.EntityFrameworkCore.MySql.

Note that if you're using Entity Framework Core 3.0, you will need the 3.0.0-rc3.final prerelease version, as per https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql#compatibility. The final 3.0 version should be released soon.

Upvotes: 1

Related Questions