Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make EF use local database in App_Data folder

I am using POCO approach on all my projects using Entity Framework. It's all good but I have one problem: It is creating database on my SQL Express, instead I want it to store my database in *.mdf file in App_Data folder.

like image 289
Stan Avatar asked Nov 05 '12 16:11

Stan


1 Answers

Set an appropriate connection string in Web.config that makes use of the AttachDBFilename keyword.

<connectionStrings>
  <add name="MyContextClassName"
       connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=True;MultipleActiveResultSets=True;AttachDBFilename=|DataDirectory|MyDatabase.mdf;User Instance=True"
       providerName="System.Data.SqlClient" />
</connectionStrings>
like image 196
bricelam Avatar answered Sep 28 '22 05:09

bricelam