How to specify a custom folder path in which EF code-first approach create a database?
By default, EF code first will create a database in
C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA
Is it possible to change this default path开发者_如何学JAVA to my own path?
Try following connection string.
<add name="default" connectionString="Data Source=.\sqlexpress;Initial catalog=TestDb;AttachDbFilename=c:\MyDatabase.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
Note that folder where you want to put your database files must be created manualy (SQL server will not do it for you).
Hope this helps.
As far as I can tell, the only way you can change the destination folder is if you are using SQL Compact Edition (SQLCE) and the SqlCeConnectionFactory factory.
It takes the destination path from the connection string (or uses |DataDirectory| by default), which is currently only supported with SQLCE.
Best I could find was this link http://blogs.msdn.com/b/adonet/archive/2010/09/02/ef-feature-ctp4-dbcontext-and-databases.aspx which applies to the CTP4 (not the latest version).
I couldn't find any way to change the output path even with web/app.config changes.
精彩评论