Reputation: 109
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
public class CommanderContext : DbContext
{
public CommanderContext(DbContextOptions<CommanderContext> opt) : base(opt)
{
}
public DbSet<Command> Commands { get; set; }
}
}
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"CommanderConnection": "Server=localhost;Initial Catalog=CommanderDB,User ID=CommanderApi;Password=*****;"
}
}
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
Upvotes: 0
Views: 1839
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