Entity framework 无法打开登录请求的数据库

Entity framework 无法打开登录请求的数据库,entity-framework,.net-core,Entity Framework,.net Core,我读了弗里曼MVC的书。当我在nuget控制台上放置“添加迁移初始值”时: `An error occurred while calling method 'BuildWebHost' on class 'Program'. Continuing without the application service provider. Error: Cannot open database "SportsStore" requested by the login. The login failed.

我读了弗里曼MVC的书。当我在nuget控制台上放置“添加迁移初始值”时:

`An error occurred while calling method 'BuildWebHost' on class 'Program'. Continuing without the application service provider. Error: Cannot open database "SportsStore" requested by the login. The login failed. Login failed for user 'DESKTOP-3IVHO1V\myname'.
据我所知,出现此问题的原因是没有具有此名称的表。例如,如果删除SportsStore的名称,则一切都正常(几乎正常)。那么,如何使一切工作,也就是说,创建一个表

我的连接字符串:

Server=(localDB)\\MSSQLLocalDB;Database=SportsStore;Trusted_Connection=True;MultipleActiveResultSets=true
和startup.cs:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using SportsStore.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.EntityFrameworkCore;

namespace SportsStore
{

    public class Startup
    {
        IConfigurationRoot Configuration;

        public Startup(IHostingEnvironment env)
        {
            Configuration = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json").Build();
        }

        public void ConfigureServices(IServiceCollection services)
        {
                        services.AddDbContext<ApplicationDbContext>(options =>
                            options.UseSqlServer(
                                Configuration["Data:SportStoreProducts:ConnectionString"]));

            services.AddTransient<IProductRepository, EFProductRepository>();
            services.AddMvc();

        }

        public void Configure(IApplicationBuilder app,
            IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.UseDeveloperExceptionPage();
            app.UseStatusCodePages();
            app.UseStaticFiles();
            app.UseMvc(routes => {
                routes.MapRoute(
                    name: "pagination",
                    template: "Products/Page{page}",
                    defaults: new { Controller = "Product", action = "List" });
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Product}/{action=List}/{id?}");
            });

        }
    }
}
使用Microsoft.AspNetCore.Builder;
使用Microsoft.AspNetCore.Hosting;
使用Microsoft.AspNetCore.Http;
使用Microsoft.Extensions.DependencyInjection;
使用Microsoft.Extensions.Logging;
使用SportsStore.Models;
使用Microsoft.Extensions.Configuration;
使用Microsoft.EntityFrameworkCore;
命名空间体育商店
{
公营创业
{
i配置根配置;
公共启动(IHostingEnvironment环境)
{
配置=新的ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile(“appsettings.json”).Build();
}
public void配置服务(IServiceCollection服务)
{
services.AddDbContext(选项=>
options.UseSqlServer(
配置[“数据:SportStoreProducts:ConnectionString”]);
services.AddTransient();
services.AddMvc();
}
公共无效配置(IApplicationBuilder应用程序,
IHostingEnvironment env,iLogger工厂(Logger工厂)
{
app.UseDeveloperExceptionPage();
app.UseStatusCodePages();
app.UseStaticFiles();
app.UseMvc(路由=>{
routes.MapRoute(
名称:“分页”,
模板:“产品/页面{Page}”,
默认值:新建{Controller=“Product”,action=“List”});
routes.MapRoute(
名称:“默认”,
模板:“{controller=Product}/{action=List}/{id?}”);
});
}
}
}

我以前遇到过这个问题,但在EF Core中没有。解决方法是将连接字符串加载到数据库中,修改它(将数据库切换到主数据库),登录,创建基本数据库,然后像往常一样滚动代码。不知道Core是否有一个等价类。如果没有,您必须自己解析它。还不错。