0

I have a windows form application that I made for a local club. I'm using inno setup to create the exe.
It defaulted the install location to program files where I learned that it makes the DB read only. With some reading I found out that the best way to set up a program is to use program files for the app and app data for the DB. How do I go about changing my program and my setup to use those different locations by default?

I have this in a utility class:

public static readonly string APP_FOLDER = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); 
public static readonly string DB_FILE_PATH = Path.Combine(APP_FOLDER, "train.sqlite3"); 
public static readonly string DB_BACKUP_FILE_PATH = Path.Combine(APP_FOLDER, "backup.sqlite3"); 
public static readonly string CONN_STR = string.Format("Data Source={0};Version=3;", DB_FILE_PATH); 

And this in DAOs:

using(SQLiteConnection conn = new SQLiteConnection(Utility.CONN_STR))
{ 
}
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Thranor
  • 393
  • 1
  • 4
  • 13

1 Answers1

2

For the setup part your answer is here

Write to AppData directory using InnoIDE?

To read from the DB, well I can't give you an exact answer because I have no idea how you access the DB, but in .NET you access the appdata folder path with

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

Hopefully from that you can set the path to your DB in your connection string.

I have this in a utility class

public static readonly string APP_FOLDER = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); 
public static readonly string DB_FILE_PATH = Path.Combine(APP_FOLDER, "train.sqlite3");
public static readonly string DB_BACKUP_FILE_PATH = Path.Combine(APP_FOLDER, "backup.sqlite3");
public static readonly string CONN_STR = string.Format("Data Source={0};Version=3;", DB_FILE_PATH);

and this in DAOs

using(SQLiteConnection conn = new SQLiteConnection(Utility.CONN_STR)) { }
Thranor
  • 393
  • 1
  • 4
  • 13
Jim W
  • 4,866
  • 1
  • 27
  • 43