Where is the SQL Server Compact file?

半世苍凉 提交于 2019-12-10 18:20:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!