Change default location of LocalDb

entity-framework localdb

Question

I want to utilize LocalDb since I am first learning to develop in EF5-code. How can I modify the LocalDb database file's default location? According to http://blogs.msdn.com/b/sqlexpress/archive/2011/10/28/localdb-where-is-my-database.aspx, the default location is the percent USERPROFILE percent directory.

The SqlCe DbConnectionFactory that allows a parameter for database path/name was what I was using before. When I use the AttachDbFileName option, if the database doesn't already exist (it's intended to build it! ), an error is raised.

1
13
1/2/2017 5:55:35 PM

Accepted Answer

This worked for me thanks to these words. There is an easy solution. In essence, I added

  <connectionStrings>
<add name="DataModel.Context" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=database;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\database.mdf" providerName="System.Data.SqlClient" />

Added the app.config's settings section, and it miraculously changed "database" with the name of my real database (DbContext). If the database is empty, EF code first also flawlessly creates it.

20
5/23/2017 12:17:58 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow