7

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?

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
codeulike
  • 22,514
  • 29
  • 120
  • 167

2 Answers2

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:

  • 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.
Sasha
  • 1,958
  • 1
  • 19
  • 33
0

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.

saluce
  • 13,035
  • 3
  • 50
  • 67
Joe.P
  • 319
  • 4
  • 10
  • 1
    Thanks Joe but its a bit more complicated than that. Its pretty obvious that App_data would be used for web apps, its less obvious how it might work for windows apps. e.g see the AppDomain.SetData method as mentioned by Sasha. Also, Saluce, thanks for the edit. – codeulike Jun 18 '12 at 09:25