Full path vs relative path
One of the reasons why it's hard-to-work with database files before are the full path to the database was serialized In different places. This made it harder to share a project and also to deploy the application. In this version, the. NET runtime added. DATADIRECTORY macro. This allows Visual Studio to put a special variable in the connection string that would be expanded at Run-time. So instead of have a connection string like this:
"Data source=.\sqlexpress; Attachdbfilename=c:\program Files\app\data.mdf "
You can have a connection string like this:
"Data source=.\sqlexpress; attachdbfilename=| Datadirectory|\data.mdf "
This connection string syntax are supported by the SqlClient and OLE DB managed providers.
By default, the | datadirectory| Variable'll be expanded as follow:
-For applications placed in a directory of the user machine, this'll be the app's (. exe) folder.
-For apps running under ClickOnce, this is a special data folder created by ClickOnce
-For Web apps, this would be the App_Data folder
Under the hood, the value for | datadirectory| Simply comes from a property on the app domain. It is possible to change that value and override the default behavior by doing this:
AppDomain.CurrentDomain.SetData ("DataDirectory", NewPath)
https://blogs.msdn.microsoft.com/smartclientdata/2005/08/26/working-with-local-databases/
Official description of the DataDirectory in the database connection string