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.
1 Answer
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>
6 Comments
Stan
But the thing is that database is not created in my App_Data folder. It's created straight in SQLEXPRESS
bricelam
@Stanislav Did you try the answer? "AttachDBFilename=|DataDirectory|..." will create the database file inside of App_Data.
Stan
I tried and it showed me
Exception has been thrown by the target of an invocation. when I did update-database -f -v.bricelam
@Stanislav Do you have any additional information? Does
$Errors[0].Exception.InnerException.ToString() tell your more?Stan
As it happends I upgraded to Win8 and now I don't even have SQLEXPRESS installed. Now it does what it is suppose to do - storing everything in file w/o even using database server.
|