Skip to main content
deleted 3 characters in body
Source Link
Steve
  • 216.6k
  • 22
  • 242
  • 296

Suppose you deploy your app.config with this connectionstring

"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\yourFile.accdb;"

In a WinForms application the |DataDirectory| shortcut represent your application working folder, but you can change at runtime where it points to using to 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");

It eliminates the need to hard-code the full path which, has you have discovered, leads to several problems to resolve during install. Of course your setup should deliver your database in your user choosen path.

Suppose you deploy your app.config with this connectionstring

"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\yourFile.accdb;"

In a WinForms application the |DataDirectory| shortcut represent your application working folder, but you can change at runtime where it points to using to 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");

It eliminates the need to hard-code the full path which, has you have discovered, leads to several problems to resolve during install. Of course your setup should deliver your database in your user choosen path.

Suppose you deploy your app.config with this connectionstring

"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\yourFile.accdb;"

In a WinForms application the |DataDirectory| shortcut represent your application working folder, but you can change at runtime where it points to using 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");

It eliminates the need to hard-code the full path which, has you have discovered, leads to several problems to resolve during install. Of course your setup should deliver your database in your user choosen path.

Source Link
Steve
  • 216.6k
  • 22
  • 242
  • 296

Suppose you deploy your app.config with this connectionstring

"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\yourFile.accdb;"

In a WinForms application the |DataDirectory| shortcut represent your application working folder, but you can change at runtime where it points to using to 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");

It eliminates the need to hard-code the full path which, has you have discovered, leads to several problems to resolve during install. Of course your setup should deliver your database in your user choosen path.