SQL Server精简“数据目录”在连接字符串宏 - 更多信息需要 [英] SQL Server Compact 'Data Directory' macro in Connection String - more info needed

查看:167
本文介绍了SQL Server精简“数据目录”在连接字符串宏 - 更多信息需要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此​​,如这个MSDN页面,当你定义一个连接字符串 SQL Server精简3.5,可以使用数据目录微距,这样的:

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:

这个MSDN网页:

数据目录支持
  SQL Server精简3.5现在支持数据目录宏。这意味着,如果你添加字符串| DataDirectory目录| (括在管道符号)到一个文件路径,这将解决该数据库的路径。

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:

数据源= C:\ Program Files文件\ MyApp的\ Mydb.sdf

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

在使用数据目录,你可以改用下面的连接字符串:

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

数据源= | DataDirectory目录| \ Mydb.sdf

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

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

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

不过,在MSDN上的获取更多信息链接实际上并没有提供任何更多的信息。

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

所以我的问题是:

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

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?

推荐答案

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

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:

  • 对于应用程序被放在一个该 在用户的计算机上的文件夹,则 数据库文件夹使用应用程序 文件夹中。
  • 对于正在运行的应用程序 的ClickOnce下,数据库文件夹 使用由特定的数据文件夹 创建。
  • 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.

这篇关于SQL Server精简“数据目录”在连接字符串宏 - 更多信息需要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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