I'm trying to create a database called Todo with Entity Framework. I want this database to appear in Sql Server Management after it has been created.
I have the context file:
namespace Domain
{
//Associate the model with the database
//This class then automatically defines a property for each table in the database that I want to work with.
public class EFDbContext : DbContext
{
public EFDbContext() : base("EFDbContext")
{
}
public DbSet<List> Lists { get; set; }
public DbSet<Task> Tasks { get; set; }
}
}
I have my Initializer:
namespace Domain
{
public class ListRepository : System.Data.Entity.DropCreateDatabaseIfModelChanges<EFDbContext>
{
protected override void Seed(EFDbContext context)
{
var todo = new List<List>
{
new List { Day="Månadg" },
new List { Day="Tisdag" },
new List { Day="Onsdag" },
new List { Day="Torsdag" },
new List { Day="Fredag" }
};
todo.ForEach(t => context.Lists.Add(t));
context.SaveChanges();
}
}
}
And here I have my Web.Config:
<connectionStrings>
<add name="EFDbContext" connectionString="Data Source=localhost\SQLEXPRESS;Initial Catalog=Todo;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
</connectionStrings>
<contexts>
<context type="todo.domain.EFDbContext, todo">
<databaseInitializer type="todo.domain.ListRepository, todo"></databaseInitializer>
</context>
</contexts>
When I run my application, I Data Connections Is created In Server Explorer as In the picture below:
When I click on this Data Connection, I get the following error message:
When I check In Sql Server Management, no database is listed there. What am I doing wrong here? Why is the not database created?
As you can see, I have a solution called Todo, and In the Todo-solution, I have three projects. I have the DbContext In the Domain-project.
1条答案
按热度按时间polhcujo1#
From your screenshot, it says login failed for user Bryan in your message. This would mean Bryan is unable to connect
Check the following 3 items
add Bryan as a user giving him DBO rights
Authentication type
Check is Mixed Mode authentication is enabledSA
role