C# 与网络相关或特定于实例的C错误#

C# 与网络相关或特定于实例的C错误#,c#,C#,我得到一个类似这样的错误: 建立与SQL Server的连接时发生与网络相关或特定于实例的错误。找不到服务器或无法访问服务器。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。(提供程序:TCP提供程序,错误:40-无法打开到SQL Server的连接) 这是我的apppsetting.json: "DBInfo": { "Name": "MySQLconnect", "Conne

我得到一个类似这样的错误:

建立与SQL Server的连接时发生与网络相关或特定于实例的错误。找不到服务器或无法访问服务器。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。(提供程序:TCP提供程序,错误:40-无法打开到SQL Server的连接)

这是我的
apppsetting.json

  "DBInfo": 
  {
    "Name": "MySQLconnect",
    "ConnectionString": "server=localhost;user Id=root;password=root;database=cinemapanda4;"
  }
这是我的
StartUp.cs

public class Startup
{
   public Startup(IConfiguration configuration)
   {
      Configuration = configuration;
   }
   public IConfiguration Configuration { get; }

   // This method gets called by the runtime. Use this method to add services to the container.
   public void ConfigureServices(IServiceCollection services)
   {
      services.AddSession();
      services.AddDbContext<MyContext>(options => options.UseSqlServer(Configuration["DBInfo:ConnectionString"]));
      services.AddControllersWithViews();
   }

   // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
   public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
   {
      app.UseDeveloperExceptionPage();
      app.UseStaticFiles();
      app.UseRouting();
      app.UseSession();
      app.UseAuthorization();
      app.UseEndpoints(endpoints => {
         endpoints.MapControllerRoute(
            name: "default",
            pattern: "{controller=Home}/{action=Index}/{id?}");
      });
   }
}
公共类启动
{
公共启动(IConfiguration配置)
{
配置=配置;
}
公共IConfiguration配置{get;}
//此方法由运行时调用。请使用此方法将服务添加到容器中。
public void配置服务(IServiceCollection服务)
{
services.AddSession();
services.AddDbContext(options=>options.UseSqlServer(配置[“DBInfo:ConnectionString]”);
services.AddControllersWithViews();
}
//此方法由运行时调用。请使用此方法配置HTTP请求管道。
public void配置(IApplicationBuilder应用程序、IWebHostEnvironment环境)
{
app.UseDeveloperExceptionPage();
app.UseStaticFiles();
app.UseRouting();
app.UseSession();
app.UseAuthorization();
app.UseEndpoints(端点=>{
endpoints.MapControllerRoute(
名称:“默认”,
模式:“{controller=Home}/{action=Index}/{id?}”);
});
}
}

我正在使用MacBook,如何解决此问题?

看起来您正在尝试使用带有EF Core的MySQL数据库,但连接到SqlServer驱动程序,但无法正常工作。要连接到MySQL,可以使用


可在此处找到的配置:

您的代码显示
UseSqlServer
,但在配置文件中有
MySQLconnect
,您是使用MySQL还是使用Microsoft SQL Server?请注意,“SQL Server”是产品的名称,Microsoft SQL Server,它并不意味着“支持SQL的服务器”。因此,如果您试图连接到MySQL,则不能使用
UseSqlServer
,你需要使用其他东西。你能用SSMS连接到那个数据库吗?我正在使用MySQL,但当我更改
选项时。使用SQLServer
选项。MySQL
并运行命令
dotnet ef database update-v
它会导致我错误
构建失败。使用dotnet build查看错误。
期望使用SQL Server驱动程序连接到MySQL是不现实的。