Cannot open the database requested at login. Login failed for user ''

I am trying to create a database using DbContext 'MyDbContext'.

I am using SQL Server 2008 R2 with SQL Server and Windows Authentication.

My DbConfiguration:

public class HostDbConfiguration : DbConfiguration
{
    public HostDbConfiguration()
    {
        SetProviderServices("System.Data.SqlClient", System.Data.Entity.SqlServer.SqlProviderServices.Instance);
        SetDefaultConnectionFactory(new LocalDbConnectionFactory("v8.0", @"Server=Eran-PC;MultipleActiveResultSets=True;Trusted_Connection=true"));
    }
}

The database must be created from DbContext, but when it is initialized

Database.SetInitializer(new DropCreateDatabaseIfModelChanges<MyDbContext>());
using (var db = new MyDbContext())
{
     db.Database.Initialize(true);
}

I get the following exception:

Cannot open the database "MyDB" requested at login. Login failed.

Login failed for user "Eran-PC \ Eran".

Any ideas?

Side note:

"Eran" SQL Server, "" "", SQL Server Management Studio, .

MyDB,

'dbo.__ MigrationHistory'

, ?

:

sqlauthority , UserMapping , a Eb DbConfiguration?

0

All Articles