0

I'm trying to push to GitHub a Windows Forms VB.Net application which does CRUD operations on a local SQLite database file, but I realized the db3 file and System.Data.SQLite.dll are excluded from the push because the contents of bin/Debug folder where they're located are a part of the .gitignore policy template on Visual Studio, which absolutely makes sense.

I have tested the .exe file out of this Debug development folder and couldn't run the application either, throwing the exception: "Could not load file or assembly 'System.Data.SQLite, Version=1.0.116.0, Culture=neutral, PublicKeyToken=...' or one of its dependencies"

My Problem is all the guides I've checked to use a SQLite in a Windows Forms project place the database file in bin/Debug, I guess for the simplicity of the tutorial. So this way of referencing the SQLite db3 in bin/Debug works fine in my application:

Public dbFullPath As String = Application.StartupPath & "\\myDatabase.db3"
Public conStr As String = String.Format("Data Source = {0}; version = 3;", dbFullPath)

However, I don't know how to place the database at the same level of other project files like .vb Forms and the Resources folder and reference it so the app works and all the necessary files are pushed to my public repository.

I created an App_Data folder at project level and placed the database file inside and then tried to replace the path String from:

Public dbFullPath As String = Application.StartupPath & "\\myDatabase.db3"

to this:

Public dbFullPath As String = "App_Data\\myDatabase.db3"

But I'm unable to open the database in a different place other than bin/Debug.

Thank you very much for your help.

alejandroMAD
  • 251
  • 2
  • 13
  • If it was me, being an SQLite DB I would be looking at creating it at RunTime and save it in the user profile using something like Environment.SpecialFolder.ApplicationData or CommonApplicationData – Hursey Dec 05 '22 at 19:40
  • [Here's a step-by-step answer from 2020 that says you can put your .db where ever.](https://stackoverflow.com/a/65482510/3585500) – ourmandave Dec 05 '22 at 23:17

1 Answers1

1

In order to run the application outside of the visual studio environment you will need to copy both the x64 and x86 folders which are generated at build time

In Chem4Word we use the NuGet package SQLite 1.0.117 to read and write to a SQLite database which is deployed to C:\ProgramData\Chem4Word, but it could be anywhere in the file system to suit your purpose.

Our installer also deploys the contents of the above folders (x64 and x86) beneath the application folder in C:\Program Files (x86)\Chem4Word as shown below The "seed" database is stored as an embedded resource, hence gets checked in to the repository.

Example directory structure