简体   繁体   中英

Stuck on EntityFramework update-database

For a ton of times I have used entity framework core and code-first migrations it's the first time I'm stuck.

In my project, everything is running in docker so is my database. I exposed port 1433 so I was able to externally use ssms <- this works i can connect with a user.

When I try to do update-database to push my migrations I got the error login failed: container_id\guest.

Now I'm wondering why it tries to connect with container_id and guest user while sa is specified in the connectionstring. The default project is my API endpoint which contains my application context class as well as my migrations.

question: Can someone explain to me what i'm doing wrong?

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"

}

connetionstring in appsettings, in appsettings.development my real secrets are filled in which should override appsettings if i'm correct.

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

I also have this in my application builder.

I think it's the Integrated Security=false part of your connection string that needs to be there.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM