ConnectionString always points to SQLEXPRESS?

Jan 14, 2011 at 4:40 PM

For some reason, no matter what I change to the ConnectionString, it always point to the default SQLEXPRESS instance. I've tried to Find All and removed anything with SQLEXPRESS, yet, every time I run the solution (CodeFirst), it kept pointing to SQLEXPRESS? Any idea why? I'm using VS 2010 WD Express version so there are some solution item that I couldn't open, perhaps that's the problem?

Thanks,

Kenny.

Jan 14, 2011 at 4:50 PM

Just some more info, even if I remove the connection string completely, it still points to the SQLEXPRESS instance with the MvcOpenId database.

Thanks.

Coordinator
Jan 15, 2011 at 7:22 PM

The connection string that's in the web.config is actually just for the EF4 (no Code-First). Apparently I forgot to remove it while making the EFCodeFirst branch. I'll fix that when I get the chance.

I'm not sure how Code-First chooses the database, but I do know that SQLEXPRESS is the default DB it looks at. I didn't yet experiment with other databases, but I imagine you have to add a connection string with UserContext as it's name. But the database name for CF is defined in UserContext.cs:

 

public UserContext()
    : base("MvcOpenID")
{ }

 

I imagine this wouldn't override the ConnectionString database name though. These are you guesses at this point which I need to test out.

In the meanwhile take a look at the "Mapping to an existing database" section of this article: http://blogs.msdn.com/b/adonet/archive/2010/12/06/ef-feature-ctp5-code-first-walkthrough.aspx

 

Hope I helped,

Goran

Jan 16, 2011 at 6:31 PM

I'm not sure what was the problem :) What I did was to copy the code to a new project and it's working nicely!

Thank you.

Coordinator
Jan 16, 2011 at 7:08 PM

I'm glad it works. I will check this out when I get the chance, but at the moment I'm swamped with some other work.