2

I am using access db which is in bin/debug folder and use it in code like

    private static string **_strCon** = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + 
***Application.ExecutablePath.ToString().Substring(0, 
Application.ExecutablePath.ToString().LastIndexOf('\\')) +
 "\\Reporting.accdb***;Jet 

OLEDB:Database Password=abc;";

and for reports I use DataSet which is using connectionstring from app.config like

    <add name="GarzaReportingSystem.Properties.Settings.ReportingConnectionString" 

connectionString="Provider=Microsoft.ACE.OLEDB.12.0;***Data Source=|DataDirectory|\bin

\Debug\Reporting.accdb***;Persist Security Info=True;Jet OLEDB:Database Password=abc" providerName="System.Data.OleDb"/>

PROBLEM:

When I make setup of the project and than install the application. I need to put Reporting.accdb in root folder in order for my forms to work using _strCon. In Other words my Executable path becomes root folder

But for DataSet

I need to put access db in bin/debug folder for it to work when application is installed.

How to solve this problem so both resolve same path like root has folder DataBase and both use that path.

2
  • while creating setup files add .accdb file in 'Application Folder'
    – deepi
    Commented Sep 14, 2011 at 7:24
  • @deepi , That means I need to change app.config path to root all the time when I make setup? . Because app.config path don't work when i prepare setup.
    – Pirzada
    Commented Sep 14, 2011 at 7:47

2 Answers 2

3

you should not hardcode any bin/debug because in deployment you will have the application running from any other installed path, to get the directory path of the exe do this:

var executingFolder = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

then something like:

var dbPath = System.IO.Path.Combine(executingFolder, "data\MyDbName.mdb");

if you include your MyDbName.mdb file in the project in a folder called data then you can set in Visual Studio first and in the installer afterwards that such data subfolder will always be deployed under bin/debug in debug or in the final application installation folder.

0
2

You should not deploy a DB in your installation directory: Write access in C:\Program Files and subdirs requires Admin privileges. You should better copy it in your directory under ProgramData.

Better yet, if you want different Windows users to have their own copy of the DB: When your program starts, it should look for a copy of the DB in current user's AppData folder. If there's no copy available, your program should first copy the file from \Program Files\blah\ to user's AppData.

Answers to this question show how to retrieve the AppData path.

1
  • How do I achieve that for AppData. Do you have any code to share?
    – Pirzada
    Commented Sep 14, 2011 at 7:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.