1

im new to mvc and im trying out some stuff with code first. im currently having problems with my dbase, whenever i build my application the build finishes successfully but i dont see my dbase get created whenever i check my local server. was wondering if there's something im missing on my connection string.

<connectionStrings>
 <add name="mydbase" connectionString="Data Source=localhost;Database=mydbase;Trusted_Connection=yes;" providerName="System.Data.SqlClient" />
</connectionStrings>

or maybe i should be looking at the global file? i just added an initializer there for the seed and nothing more, i dont see any reason why that would mess that up...

thanks in advance!

2 Answers 2

1

The database isnt committed until you've used the Context to which it relates.

For example, in a test project, I called my initializer

 Database.SetInitializer<TestContext>(new TestContextInitializer());

and then used the context for some task i.e.

_testContext = new TestContext();
var stuff = from te in _testContext.TestTable select te;

It's at this point the db is created.

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

3 Comments

do you mean i need to call at least a field from the table? i did something like this <%: model.FirstName %> on my view and it's giving me a nullreference. and yes i have that same initializer on my global.asax which i checked using breakpoint and it seems that the app runs it on debug mode..
From what I've seen, you need to use the context in some way before the magic happens. In my test project, the db is created after executing the linq statement.
ok, you're right, i just executed an EF code and then the database was created. now im wondering as to why i can't see the database on my management studio. i just saw that the web dev express is creating the database onto the MSSQL_EXPRESS folder which is on the same level of the MSSQL10_50 folder that the management studio is looking at. is there a way where i can point the dev express to the folder where the management studio is looking at? it's ok if you dont, u already answered my question. :D
0

Normally the database gets created when you run the application, not when you build it. You may take a look at the following blog post about the different database initialization options (AlwaysRecreateDatabase, CreateDatabaseOnlyIfNotExists, RecreateDatabaseIfModelChanges).

1 Comment

yeah, i do wait for it to run before i check the dbase. i even try to run debug at the same time making sure it's running.

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.