6

I have a connection string:

<add name="Gini" providerName="System.Data.SqlClient" connectionString="user id=user;Password=pa55;Data Source=server;Database=gini" />

I want EF to be able to control the creation of the database and updates through migrations so I'm letting it have complete control over the DB.

My contact class looks like the following:

public class GiniContext : DbContext
{
    public DbSet<UserSession> UserSessions { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Configurations.Add(new UserSessionConfiguration());
    }

    public GiniContext() : base("Gini")
    {
        Database.Create();
    }
}

I would expect this to create a database called "gini" on the server called "server" using the username and password as above but it's creating it on the (LocalDB)\v11.0 instance.

What am I doing wrong?

4
  • Tried naming it "GiniContext"? Commented May 22, 2013 at 15:39
  • I think for that to run properly the Context itself and the connection string must have the same name, so try renaming the connection string in your config to "GiniContext" Commented May 22, 2013 at 15:39
  • I've tried renaming the connection string to "GiniContext" and changing the name in the constructor as well. Commented May 22, 2013 at 15:41
  • 1
    @roughnex can you add that as an answer. That worked thank you. Commented May 22, 2013 at 15:47

1 Answer 1

2

If you have two projects like a Class Library for Objects and a Web Application referencing it. You ll need to add the connection from app.config to the web.config in your web application.

Sign up to request clarification or add additional context in comments.

2 Comments

Does it have to be in both the class library and web application? Or can it just be in the web application?
I just checked in one of my projects and the app config doesn't have it but the web config does have it. This thread has some info about it. stackoverflow.com/questions/4290919/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.