I built a database structure with codefirst EF from a tutorial but I can't find the database.

I've looked in (localdb) and it's not in my local install of SQLServer. Would anybody know where I would need to look to find the database?

1 Year
Discussion Span
Last Post by lithium112

Depends on what tutorial you've been following. You can code against an existing database (in which it's your job to create it) or you can code against a new database where your context will attempt to create the database when needed. In both cases, of course, you need something to host the database like SQL Server.

So...what tutorial are you following so we have a better idea of what your project looks like?


deceptikon - he says hes doing codefirst so the code will generate the database - where it does that depends on the connection string.

Edited by DaveAmour


hes doing codefirst so the code will generate the database

That's an unwarranted assumption. Code first doesn't unconditionally generate a database; how you've defined your context specifies what EF does with the model to maintain database integrity.

where it does that depends on the connection string

Indeed, it does. But would you rather direct an apparently new programmer to the location of the connection string in a project that you haven't seen, or simply get a URL to the tutorial being followed so you have a reasonable expectation of what the project looks like? ;)


Sorry I'm confused. If a code first approach doesn't generate your database from your models then where does the database come from?


Just thought - are you talking bout manually creating an empty database and then using code first? In that case yes then code first is not actually creating the database as such, it is creating the database tables etc.

The connection string, which is almost certainly in a .config file is the easiest place to find the database though in my oppinion. I also suspect that the OP didn't create the database manually otherwise they would know where it is I would hope!


In that tutorial there is the following - does that help?

Where’s My Data?

By convention DbContext has created a database for you.
If a local SQL Express instance is available (installed by default with Visual Studio 2010) then Code First has created the database on that instance
If SQL Express isn’t available then Code First will try and use LocalDb (installed by default with Visual Studio 2012)

There is a link in there too on the actual page telling you about LocalDb.


I looked at those database connections, localdb and ssms. I don't have express. I also looked at the link provided. For some odd reason, I don't see it anywhere. I know it was created somewhere though since VS was doing work to get it set up. Unfortunately it didn't have anything in the console about where it put the database.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.