Entity Framework 7 and login failed

asp.net asp.net-mvc c# entity-framework-core

Question

I'm trying to work with ef7 and asp.net mvc 6, but when i try to work with db there comes following exceptions:

Cannot open database "Posts" requested by the login. The login failed.

Login failed for user 'alexpc\Alexandr'.

In DbContext class i use following code:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    optionsBuilder.UseSqlServer(@"Data Source=alexpc;Database=Posts;Integrated security=True;");
}

It seems like ConnectionString is right, where can there be the problem?

Accepted Answer

Problem is solved in this way: It turned out, that the exception "Login failed for user "Username"" raised, when before the first launch migration was not made by the hand. It automatically worked for "Code First" in the EF6, but in EF7 this feature was off. To perform migration you need a DNVM, which you can install using guide from this page: https://github.com/aspnet/home Then you need to open command prompt and change directory to your project (where "project.json" file is located ) and type the following commands:

dnx . ef migration add
dnx . ef migration apply

If you did everything right, "Migration" folder must appear in your project directory. Now you can run your project without this exception!




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why