When you try to connect to SQL EXPRESS without a created database, the Entity Framework Core throws out ambiguous content exception: password incorrect database or database does not exist

enter image description here Could not open database "..." requested by login. Login failed. An error occurred while logging in to the user "..."

Moreover, if a database is created, it will start swearing at the name of the object, while not changing it, nothing will happen ... enter image description here "SqlException: Invalid object name" ... ".

Followed the guide from Microsoft, here is the link https://docs.microsoft.com/en-us/ef/core/ enter image description here

Maybe I missed something?

    1 answer 1

    Entity Framework Core no longer creates tables and databases automatically. For this you need to trigger a migration. From the C # code, you can do it like this:

    public class DatabaseContext : DbContext { public DatabaseContext() { if (Database.EnsureCreated()) Database.Migrate(); //Если базы данных не существует - создает миграцию } //public DbSet<Project> Projects { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(@"Server=.\SQLEXPRESS;Database=RusEngDb;Trusted_Connection=True;"); } } 
    • In VB.NET (not sure about C #), the SQL Compact provider, I just call Database.EnsureCreated (), that's enough - the file is created if it is not there. Version EF Core 2.1 - Gennady Danylchenko