问题
I have an ASP.NET MVC project that uses a SQL Server Compact database. I have the following connection string for my FoobarContext
:
<add name="FoobarContext"
connectionString="Data Source=|DataDirectory|Foobar.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
I fired up the project and it appears to persist data as expected. However, I can't find a file named 'Foobar.sdf' anywhere. What am I missing?
Update: It wasn't taking my connection string. Setting a breakpoint and inspecting the context, I found its ConnectionString was actually the following:
Data Source=.\\SQLEXPRESS;Initial Catalog=MvcApplication3.Infrastructure.Data.FoobarContext;Integrated Security=True;MultipleActiveResultSets=True
Mystery solved.
回答1:
It definitely should be ~/App_Data by default, but you can try running AppDomain.CurrentDomain.GetData("DataDirectory")
to see where ASP.Net thinks the directory exists.
If this reveals nothing of interest, you may want to make sure your windows explorer is set to show hidden files, just in case that's why you don't see the file.
回答2:
It should be in a folder called App_Data off the root of your MVC project.
回答3:
you should be stingy on the app folder in your project, the database file you'll find inside.
Regards
来源:https://stackoverflow.com/questions/7343113/where-is-the-sql-server-compact-file