Visual Studio 11 brings a new development database — SQL Server Local Database. Bye bye SQL Server Express dependency.
I typically let Code First run with it’s default database of choice – up to now that’s been SQL Server Express — when I’m creating simple samples where I don’t care too much about keeping the sample database around.
But I’m so used to opening up SSMS to look at detailed information about the database, especially when Code First is involved in creating it’s schema. I like to see what’s happening.
In Visual Studio 2010’s server explorer, I can’t typically glean the details I’m after. (Maybe I need more instruction here? ) For example, I have to open a column’s properties window to see details.
In SSMS, I prefer the view:
With EF5 however, the default database for code first is the new SQL Server 2012 LocalDb.
When you add EntityFramework 5 to your project it adds some configuration elements to the application’s config file and in there is where EF is setting the default ConnectionFactory for Code First to use LocalDb.
NOTE: April 3, 2012: This connection factory info has changed a bit with EF 5 Beta 2. See this updated blog post: Update to EF5 and DbLocal Default in Config
I’m sure lots of people won’t think to look in there and will just be happy that the database is magically there. (Not me. I can’t bear not knowing how things work. )
So if you want to look at your data, forget the Server Explorer. Check out the new SQL Server Object Explorer in Visual Studio. It will look very familiar … if you use SSMS, that is. They’ve pulled the explorer from SSMS into Visual Studio and improved upon it. Very nice!!
Also, take note that last time I checked, you could not open up localdb databases in SSMS. That may not longer be the case. But I don’t feel like installing full blown SQL Server on my virtual machine to verify since I now have what I need inside of Visual Studio.
To see your database in the new Object Explorer:
1. Click the New Database icon/glyph/blob (circled)
2. In Connect to Server window, TYPE IN “(localdb)/v11.0”. Don’t click the dropdown unless you want to wait for the wizard to explore the outer reaches of the universe for every possibly accessible SQL Server instance.
3. Then after connecting, you can expand the new connection to explore your database, in detail, inside of Visual Studio. (yay)
There are some nice improvements over the SSMS 2008 UI I’m used to. For example, if you right click a table you can choose View Data and there is an option box in the viewer to choose how many rows you want to look at. That’s just one little example. Another example is if you do something like delete a table, you will get the options of creating a script or just executing the change on the database. I’m sure you’ll find lots of information on these types of changes.
Now when you are working with Code First and using default behavior, you know where to find the database it’s created for you and how to inspect that database.
Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!
7 thoughts on “VS11 and EF5: Where’s that database that Code First created?”
Thanks Julie. A good post. I plan to pull down the beta later this week and get a virtual test environment going so this is useful to know.
I’m curious to learn if there are any real limitations during development of using SQL local DB and how easy it is to move it to full blown SQL Instance later on. Also is there any profiling available against local db?
So you have to switch from Visual Studio 2010 to VS 11 to view the localdb ??
@livingston . that sure would suck. That’s why I tried to be clear that I hadn’t checked lately so I’m not the right one to ask. 🙁
@steve…absolutely no clue. Don’t know much about localdb
Thank you very much , julie.
Hope to hear from you about validation in Silverlight with the EF soon! :).
Thanks for the post Julie.
It seems in Beta 2 the default database instance is SQLExpress if it is installed. If not it will use the LocalDb instance.
I have VS11 with SQL Server 2012 Express installed and it uses this instance directly
Hey Julie, I’m using 4.3 and when running debug it uses the datasource specified in my app.config – (localdb)\v11.0.
When I run my library from another process (a service) the datasource ends up being my sqlexpress instance – .\sqlexpress. I confirmed this by attaching to the process.
Is this expected behaviour?
Hi Stephen, sorry for the delayed reply. This makes sense. The internal default is sqlexpress. The config setting overrides that.