我正在Ubuntu Linux上使用.NetCore 3.0实体框架。我已经安装了MariaDB,添加了用户Joe以访问MariaDB。我可以使用以下方式访问数据库:
mysql -u Joe -p -h localhost
.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;");
}
}
该项目已导入两个NuGet软件包:
microsoft.EntityFrameworkCore.Design
microsoft.EntityFrameworkCore.SqlServer
当我尝试运行此代码或使用dotnet ef database update
“迁移/更新”数据库时,收到以下异常:
建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (提供者:TCP提供程序,错误:40-无法打开与SQL Server的连接)
我什至启用了对MariaDB的远程连接访问,尽管我是从数据库所在的给定计算机访问它的。
感谢您的任何建议:-)