Entity Framework 7 - Cannot open database requested by the login. The login failed

entity-framework-core

Question

I've decided to use EF7 form my "home made" web application. I created my DbContext which contains this:

protected override void OnConfiguring(DbContextOptionsBuilder options)
{
    options.UseSqlServer(@"Data Source=NameOfSQLServer;Database=MyDb;Integrated Security=True");
}

However when I run app, I've got this error:

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

That's quite shocking for me, because I used that connection string in EF6 and it worked like a charm.
Any idea what's wrong?

1
0
3/6/2016 4:20:35 PM

Popular Answer

Entity Framework does not change your connection string. It just passes this through to SqlClient. You can eliminate EF from the equation and test your connection string actually works with this code:

using (var connection = new System.Data.SqlClient.SqlConnection(connectionString))
{
    connection.Open(); // <-- this should fail if the login doesn't work
}

Chances are something is wrong in the connection string, the database setup, or both.

1
3/7/2016 9:16:22 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow