Fábio Pires
Fábio Pires

Reputation: 109

Error when trying to update database in .NET Core

I am trying to update a database in .NET Core using the command

dotnet ef database update

but I am getting the following error

Error Number:18456,State:1,Class:14
Login failed for user ''.

I can log in in my SQL Server with this User ID and password so I don´t think the problem is in my connection string

Context

   public class CommanderContext : DbContext
    {
        public CommanderContext(DbContextOptions<CommanderContext> opt) : base(opt)
        {

        }
        public DbSet<Command> Commands { get; set; }
    }
}

appsettings.cs

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "CommanderConnection": "Server=localhost;Initial Catalog=CommanderDB,User ID=CommanderApi;Password=*****;"
  }
}

Startup.cs


        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();
            services.AddDbContext<CommanderContext>(opt => opt.UseSqlServer(Configuration.GetConnectionString("CommanderConnection")));
            services.AddControllers();
            services.AddScoped<ICommanderRepo, MockCommanderRepo>();


        }

I also leave a print of my SQL Server

enter image description here

Upvotes: 0

Views: 1839

Answers (1)

Glynn Hurrell
Glynn Hurrell

Reputation: 652

Your issue is that you've got a comma in the connection string just before User Id.

This needs to be a semicolon:

 "CommanderConnection": "Server=localhost;Initial Catalog=CommanderDB;User ID=CommanderApi;Password=*****;"

Upvotes: 3

Related Questions