|数据目录|在哪里定义? [英] Where is |DataDirectory| defined?

查看:30
本文介绍了|数据目录|在哪里定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我系统上的那个文件在哪里?

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

Tons of questions and answers all over SO and the internet but I can't find any that gives an answer to this specific question.

全部是默认的,但我找不到文件本身,

All is default but I can't find the file itself,

从哪里/如何获取 |DataDirectory|定义?

Where/how gets |DataDirectory| defined?

文件保存在哪里,它甚至存在吗?如果没有,发生了什么?

Where is the file saved, does it even exist? If not, what is going on?

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

edit: The file isn't located at AppDomain.CurrentDomain.GetData("DataDirectory").ToString(); all (sqattered) answers tell me it should be. It must be somewhere as the debugger breaks nagging about the model unequals the table when I change the model. It's not there.

推荐答案

|DataDirectory| 本身并不是一个文件.来自 MSDN 一篇相当老的文章的引述:

The |DataDirectory| isn't a file per se. A quote from a rather old MSDN article:

默认情况下,|DataDirectory| 变量将按如下方式展开:

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

  • 对于放置在用户计算机目录中的应用程序,这将是应用程序的 (.exe) 文件夹.
  • 对于在 ClickOnce 下运行的应用程序,这将是一个由 ClickOnce 创建的特殊数据文件夹
  • 对于网络应用,这将是 App_Data 文件夹

实际上,|DataDirectory| 的值仅来自应用域上的属性.可以通过执行以下操作来更改该值并覆盖默认行为:

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)

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

A further quote regarding your schema inconsistencies:

使用本地数据库文件时需要了解的一件事是,它们被视为任何其他内容文件.对于桌面项目,这意味着默认情况下,每次构建项目时都会将数据库文件复制到输出文件夹(又名 bin).F5 之后,这是它在磁盘上的样子

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

 MyProjectData.mdf

 MyProjectMyApp.vb

 MyProjectBinDebugData.mdf

 MyProjectBinDebugMyApp.exe

在设计时,数据工具使用 MyProjectData.mdf.在运行时,应用程序将使用输出文件夹下的数据库.由于抄袭,很多人的印象是app没有将数据保存到数据库文件中.事实上,这仅仅是因为涉及到数据文件的两个副本.通过数据库浏览器查看模式/数据时同样适用.工具正在使用项目中的副本,而不是 bin 文件夹中的副本.

At design-time, MyProjectData.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.

这篇关于|数据目录|在哪里定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆