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 Compact 3.5定义连接字符串时,可以使用“数据目录”宏,如下所示:
quote from this msdn page:
从这个msdn页面引用:
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.数据目录支持SQL Server Compact 3.5现在支持Data Directory宏。这意味着如果添加字符串| DataDirectory | (用管道符号括起来)到文件路径,它将解析为数据库的路径。
For example, consider the connection string:
例如,考虑连接字符串:
"Data Source= c:\program files\MyApp\Mydb.sdf"
“数据源= c:\ program files \ MyApp \ Mydb.sdf”
When using Data Directory, you can instead use the following connection string:
使用数据目录时,您可以改为使用以下连接字符串:
"Data Source = |DataDirectory|\Mydb.sdf"
“数据源= | DataDirectory | \ Mydb.sdf”
For more information, see How to: Deploy a SQL Server Compact 3.5 Database with an Application.
有关更多信息,请参见如何:使用应用程序部署SQL Server Compact 3.5数据库。
However, the 'for more information' link on msdn doesn't actually give any more information.
但是,msdn上的“获取更多信息”链接实际上并没有提供更多信息。
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?
如何|数据目录|宏在运行时翻译?对于WinForm应用程序,它似乎只是给出可执行文件的位置。还是比这更复杂?
2 个解决方案
#1
7
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:
若要设置DataDirectory属性,请调用AppDomain.SetData方法。如果未设置DataDirectory属性,则将应用以下默认规则来访问数据库文件夹:
- 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.
- 对于在ClickOnce下运行的应用程序,数据库文件夹使用创建的特定数据文件夹。
#2
0
Please review this link: http://msdn.microsoft.com/en-us/library/aa478948.aspx
请查看此链接: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.
| DataDirectory |连接字符串的一部分指定MDF文件位于App_Data目录中。
#1
7
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:
若要设置DataDirectory属性,请调用AppDomain.SetData方法。如果未设置DataDirectory属性,则将应用以下默认规则来访问数据库文件夹:
- 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.
- 对于在ClickOnce下运行的应用程序,数据库文件夹使用创建的特定数据文件夹。
#2
0
Please review this link: http://msdn.microsoft.com/en-us/library/aa478948.aspx
请查看此链接: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.
| DataDirectory |连接字符串的一部分指定MDF文件位于App_Data目录中。