Search code examples
c#sqlite

Unable to open sqlite database file inside program


I'm trying to run a program I made (created a installer via Advanced Installer) but it keeps saying it can't open the database (sqlite) file. I've checked the paths and I think they match up, as it runs just fine inside Visual Studio. The App.config connection string is:

<connectionStrings>
   <add name="db" connectionString="Data Source=qbc-members.sqlite;Version=3;" />
</connectionStrings>

Here is a screenshot of the location inside the project directory:

enter image description here

Here is the actual exception message:

enter image description here

Like I said, it runs as expected when debugging inside Visual Studio. When I check where the program was installed (C:\Program Files (x86)\user\qbc) it shows the sqlite database file inside the directory with the actual .exe file. So I'm really confused on why it can't find the file (as I tried looking up answers and the answer I think is relevant is that it can't find the file). Here is a screenshot as well of the actual program directory (once installed).

enter image description here

As you can see, the file is there. Any ideas on why it is throwing this exception?

Any help would be appreciated.

Thanks!

(Sorry if my question is unclear, please let me know and I'll try to add more info if needed).


Solution

  • The problem is most likely that application does not have write access to C:\Program Files (x86)\user\qbc directory. It's required because SQLite creates a lock file in the directory with database file.

    Set directory write permissions for the user under which application is launched and the problem should be solved.