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

因此,如 on this msdn page所述,为您定义连接字符串时
sql Server Compact 3.5,您可以使用“数据目录”宏,如下所示:

引自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.

但是,msdn上的“获取更多信息”链接实际上并没有提供更多信息.

所以我的问题是:

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

解决方法

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

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

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...