sql - |DataDirectory| 在哪里定义?

标签 sql asp.net-mvc database entity-framework vwdexpress

这是 Where is that file on my system? 的后续问题

SO 和互联网上有大量的问题和答案,但我找不到任何可以回答这个特定问题的答案。

一切都是默认的,但我找不到文件本身,

它不在那里

在哪里/如何获取|DataDirectory| 定义

文件保存在哪里,是否存在?如果不是,那是怎么回事?

编辑:文件位于AppDomain.CurrentDomain.GetData("DataDirectory").ToString();所有( sqattered) 答案告诉我它应该是。它必须在某个地方,因为调试器会在我更改模型时打破关于模型不等于表的唠叨。它在那里。

最佳答案

|DataDirectory| 本身不是一个文件。引用一篇相当古老的 MSDN 文章:

By default, the |DataDirectory| variable will be expanded as follow:

  • For applications placed in a directory on the user machine, this will be the app's (.exe) folder.
  • For apps running under ClickOnce, this will be a special data folder created by ClickOnce
  • For Web apps, this will be the App_Data folder

Under the hood, the value for |DataDirectory| simply comes from a property on the app domain. It is possible to change that value and override the default behavior by doing this:

AppDomain.CurrentDomain.SetData("DataDirectory", newpath)

关于您的架构不一致的进一步引用:

One of the things to know when working with local database files is that they are treated as any other content files. For desktop projects, it means that by default, the database file will be copied to the output folder (aka bin) each time the project is built. After F5, here's what it would look like on disk

 MyProject\Data.mdf

 MyProject\MyApp.vb

 MyProject\Bin\Debug\Data.mdf

 MyProject\Bin\Debug\MyApp.exe

At design-time, MyProject\Data.mdf is used by the data tools. At run-time, the app will be using the database under the output folder. As a result of the copy, many people have the impression that the app did not save the data to the database file. In fact, this is simply because there are two copies of the data file involved. Same applies when looking at the schema/data through the database explorer. The tools are using the copy in the project, not the one in the bin folder.

关于sql - |DataDirectory| 在哪里定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12187068/

相关文章:

xml - 如何将 XML 发布到 MVC Controller 中? (而不是键/值)

php - 将具有 130 万条记录的表从一个 MysQL 服务器移动到另一个(在不同的物理服务器上)

sql - 如果特定日期的表中没有数据,则返回 0 或 Null 值?

java - 在存储的 CLOB 中包含自动增量值

asp.net-mvc - Entity Framework 6.1.3

jquery - jquery中如何将JSON字符串添加到数组中

database - Facebook 游戏开发 - 在(哪个)数据库中存储项目?

database - 如何获取自引用对象中最顶层的父级

mysql - 代码 - 1248 - 每个派生表都必须有自己的别名?

sql - 从结果中选择最大日期行