Suppose you deploy your app.config using this connection string
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\yourFile.accdb;"
In a WinForms application, the shortcut |DataDirectory|
represents the working folder of your application, but you can change it at run time, where it indicates the use of this code.
// appdomain setup information AppDomain currentDomain = AppDomain.CurrentDomain; //Create or update a value pair for the appdomain currentDomain.SetData("DataDirectory", "Your user choosen path");
This eliminates the need for hard coding of the full path, which, as you find, leads to several problems during installation. Of course, your setup should deliver your database in the path you choose.
source share