SQL Server Compact 'Data Directory' macro in Connection String - more info needed

巧了我就是萌 提交于 2019-12-08 17:34:16

问题


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?


回答1:


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.



回答2:


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.



来源:https://stackoverflow.com/questions/1612959/sql-server-compact-data-directory-macro-in-connection-string-more-info-neede

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!