在VS 2019中添加迁移后更新数据库时出错

时间:2020-04-19 15:19:15

标签: c# asp.net entity-framework visual-studio-2019

我在Visual Studio 2019中有一个使用c#和angular的项目。我在一个存储库项目中实现了数据库代码优先方法。我可以添加迁移,但是在步骤update-database中,我遇到以下错误:An error occurred using the connection to database '' on server '(localdb)\MSSQLLocalDB'.。似乎该命令无法识别我在连接字符串中传递的数据库的名称,该字符串在文件config.json中在下面突出显示:

{
  "ConnectionStrings": {
    "QuickBuyDB": "Data Source=(localdb)\\MSSQLLocalDB;Database=QuickBuyDB"

  }
}

Web项目中文件Startup.cs中用于连接的方法:

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

    var connectionString = Configuration.GetConnectionString("QuickBuyDB");
    services.AddDbContext<QuickBuyContext>(option =>
                                                    option.UseLazyLoadingProxies()
                                                    .UseMySql(connectionString,
                                                                    m => m.MigrationsAssembly("QuickBuy.Repository").EnableRetryOnFailure(3)));
    // In production, the Angular files will be served from this directory
    services.AddSpaStaticFiles(configuration =>
    {
        configuration.RootPath = "ClientApp/dist";
    });
}

有人可以告诉我我在做什么错吗?本地实例的属性中引用的连接字符串:

Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=master;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False

0 个答案:

没有答案