Reputation: 61
I am using mvc3 to develop an database application and followed the Code-First Tutorial using Entity Framework 4 of msdn site.... I followed all the steps but unable to see the sdf file.... I can perform CRUD operations but can not see the physical database file inside the app_data folder I also did "Show all file" but still it is not shown in my visual studio explorer...even my App_data folder is empty...
Code inside the web.config file:
<add name="Forum1Context"
connectionString="Data Source=|DataDirectory|\Forum.sdf"
providerName="System.Data.SqlServerCe4.0"/>
Please Help me!!
Upvotes: 0
Views: 2875
Reputation: 336
Just remove the backslash \
before Forum
. I think that will solve it.
Upvotes: 0
Reputation: 36
I experienced a similar issue. In my case, the name attribute in the add tag was not the same as the name of the class which inherited from DbContext. When I changed the name attribute to match, then I could see the .sdf file, but rows I had inserted previously into the database were lost.
Upvotes: 2
Reputation: 1018
Just wanna point out that SQL Express and SqlServer CE are different. SQL Express will need a memory pipe or TCP connection like any other DB server, and the Sql Server CE will automatically create your DB file if doesn't exist at first runtime.
Could it be that you haven't run our app (and EF4.1 code) hence your .sdf file isn't there yet?
Upvotes: 0
Reputation: 6218
"Data Source=|DataDirectory|Forum.sdf" means Database file is located at "App_Data" folder. And if you can even perform CRUD operation, Database file should be already there as "App_Data\Forum.sdf". (Please also verify with window explorer).
On Visual Studio, need to enable "Show All Files" on Solution Explorer to view Database file.
Upvotes: 0
Reputation: 1407
It could be that the Database considered your SQL Express rather then the connection string. Fire up SQL Management Studio and check your SQL Express server
Upvotes: 2