SQL Server Compact“数据目录”连接字符串中的宏 - 需要更多信息

发布于 2024-08-08 21:41:17 字数 787 浏览 3 评论 0原文

因此,正如此 msdn 页面所述,当您定义连接字符串时为了 SQL Server Compact 3.5,您可以使用“数据目录”宏,如下所示:

引用 此 msdn 页面

数据目录支持
SQL Server Compact 3.5 现在支持数据目录宏。这意味着如果您添加字符串 |DataDirectory| (用管道符号括起来)到文件路径,它将解析为数据库的路径。

例如,考虑连接字符串:

“数据源= c:\program files\MyApp\Mydb.sdf”

使用数据目录时,您可以使用以下连接字符串:

“数据源 = |DataDirectory|\Mydb.sdf”

有关详细信息,请参阅如何:使用应用程序部署 SQL Server Compact 3.5 数据库。

然而,msdn 上的“了解更多信息”链接实际上并未提供任何更多信息。

所以我的问题是:

|数据目录| 是如何工作的?宏在运行时翻译?对于 WinForm 应用程序,它似乎只给出可执行文件的位置。或者比这更复杂?

So, as described on this msdn page, when you define a Connection String for
SQL Server Compact 3.5, you can use the "Data Directory" macro, like this:

quote from this msdn page:

Data Directory Support
SQL Server Compact 3.5 now supports the Data Directory macro. This means that if you add the string |DataDirectory| (enclosed in pipe symbols) to a file path, it will resolve to the path of the database.

For example, consider the connection string:

"Data Source= c:\program files\MyApp\Mydb.sdf"

When using Data Directory, you can instead use the following connection string:

"Data Source = |DataDirectory|\Mydb.sdf"

For more information, see How to: Deploy a SQL Server Compact 3.5 Database with an Application.

However, the 'for more information' link on msdn doesn't actually give any more information.

So my question is:

How does the |Data Directory| macro translate at run time? For WinForm apps, it seems to just give the location of the executable. Or is it more complicated than that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光沙漏 2024-08-15 21:41:17

要设置 DataDirectory 属性,请调用 AppDomain.SetData 方法。如果您没有设置 DataDirectory 属性,则将应用以下默认规则来访问数据库文件夹:

  • 对于放置在
    用户计算机上的文件夹,
    数据库文件夹使用应用程序
    文件夹。
  • 对于正在运行的应用程序
    ClickOnce 下的数据库文件夹
    使用特定的数据文件夹
    创建的。

To set the DataDirectory property, call the AppDomain.SetData method. If you do not set the DataDirectory property, the following default rules will be applied to access the database folder:

  • For applications that are put in a
    folder on the user's computer, the
    database folder uses the application
    folder.
  • For applications that are running
    under ClickOnce, the database folder
    uses the specific data folder that is
    created.
阳光下的泡沫是彩色的 2024-08-15 21:41:17

请查看此链接:
http://msdn.microsoft.com/en-us/library/aa478948.aspx

|数据目录|连接字符串的一部分指定 MDF 文件位于 App_Data 目录中。

Please review this link:
http://msdn.microsoft.com/en-us/library/aa478948.aspx

The |DataDirectory| portion of the connection string specifies that the MDF file is located in the App_Data directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文