Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Entity Framework ignoring my connection string?

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?

like image 418
Piers Karsenbarg Avatar asked May 22 '13 15:05

Piers Karsenbarg


1 Answers

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.

like image 197
arunlalam Avatar answered Oct 17 '22 01:10

arunlalam