Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 7 and login failed

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?

like image 697
neonhash Avatar asked May 13 '15 16:05

neonhash


1 Answers

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!

like image 82
neonhash Avatar answered Oct 17 '22 23:10

neonhash