【问题标题】:Stuck on EntityFramework update-database卡在 EntityFramework 更新数据库上
【发布时间】:2021-05-05 09:58:46
【问题描述】:

我已经使用了很多次 entity framework core 和代码优先迁移,这是我第一次遇到困难。

在我的项目中,一切都在 docker 中运行,我的数据库也是如此。 我暴露了 1433 端口,所以我可以在外部使用 ssms

当我尝试更新数据库来推送我的迁移时,我收到错误登录失败:container_id\guest。

现在我想知道为什么它在连接字符串中指定了 sa 时尝试与 container_id 和来宾用户连接。 默认项目是我的 API 端点,其中包含我的应用程序上下文类以及我的迁移。

问题:谁能向我解释我做错了什么?

version: '3.4'

services:
  db:
    image: "mcr.microsoft.com/mssql/server:2019-latest"
    container_name: MSSQLServer
    ports:
    - "1433:1433" 
    environment:
        SA_PASSWORD: ${Api_SA_PASSWORD}
        ACCEPT_EULA: "Y"
        

  portfolio-frontend:
    image: ${DOCKER_REGISTRY-}portfoliofrontend
    build:
      context: .
      dockerfile: Portfolio-frontend/Dockerfile

  apiendpoint:
    image: ${DOCKER_REGISTRY-}apiendpoint
    build:
      context: .
      dockerfile: HeaderInfoApi/Dockerfile


"ConnectionStrings": {
"ApplicationContext": "Server=server;Database=Portfolio;MultipleActiveResultSets=true;User=username;Password=password"

}

appsettings 中的连接字符串,在 appsettings.development 中填写了我真正的秘密,如果我是正确的,应该覆盖 appsettings。

using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
        {
            var context = serviceScope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
            context.Database.Migrate();
        }

我的应用程序构建器中也有这个。

【问题讨论】:

    标签: c# asp.net .net-core entity-framework-core


    【解决方案1】:

    我认为你的连接字符串的Integrated Security=false 部分需要在那里。

    Data Source=.;Database=myDb;Integrated Security=false;User ID=sa;Password=<password>
    

    【讨论】:

    • 我解决了这个问题,显然它是服务器而不是本地主机,而是我在另一个线程中找到的您计算机的 IP 地址
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多