1

How can I use my database with another computer without changing the path?

I'm using this path

SQLiteConnection conn = new SQLiteConnection(
"data source=C:\\Users\\users\\Documents\\Visual Studio 2012\\Projects\\SKM Computerized Payroll System\\db_SKMPayroll.sqlite");
Vojtěch Dohnal
  • 7,867
  • 3
  • 43
  • 105
  • By ensuring that the same path exists on the other computer. What is the actual problem you're trying to solve? – CL. Aug 27 '17 at 07:29
  • when my program is in exe file the it will not read the program on other computer unless i change the path on that computer –  Aug 27 '17 at 08:08
  • Learn how to use `=@"data source=C:\Users\users\ ...` – Vojtěch Dohnal Aug 27 '17 at 08:54

1 Answers1

1

Do not use the path you are now using for your database file. It is a location used to store your VS project in development. When you deploy your application, you should not use any of your development folders.

You should use a dedicated folder for your database, like Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

Or you can use the folder your app is installed in, provided that the every user has read/write access to it (it should not be e.g. in ProgramFiles)

Try this one:

SQLiteConnection conn = new SQLiteConnection(
 string.Format(
   "data source={0}", 
   Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                "db_SKMPayroll.sqlite"))

If you use a database file stored in your \bin\Debug or \bin\Release folder using CopyAllways, be prepared that your development database in \bin\ folders gets ovewriten with the database file from your project.

Vojtěch Dohnal
  • 7,867
  • 3
  • 43
  • 105