Captain Otter
Captain Otter

Reputation: 43

Embed .sqlite database in .exe c# application

I want to embed the SQLite database into my C# windows form app (.exe) so I can give a very non-tech savvy client just the .exe file and nothing else. The database is read-write and I need to access its path for the DataSource like so:

 SQLconnect = new SQLiteConnection("DataSource=" + path + ";Version=3;Compress=True;");

I also tried saving the database to a folder on Desktop but SQLiteConnection.CreateFile(path) seems to fail because if I put the .exe file outside the bin/debug folder, .exe does not open at all (but it creates the necessary folder on Desktop).

But as long as it is in the bin/debug, it creates the database file and creates the tables and .exe works perfectly. There are no errors raised at any point in the application.

Upvotes: 3

Views: 4907

Answers (1)

Harsh
Harsh

Reputation: 3751

To include the SQLite dlls you will have to modify the property of the reference and mark it as Embedded Resource. You will probably have to use ILMerge See this.

You cannot embed the database. So, you have the following two choices :

  1. You can create In-Memory/Temporary database.

    var connection = new SQLiteConnection("Data Source=:memory:");

  2. Create the database on the go. On your application startup, you can create and seed the database. See this.

Upvotes: 4

Related Questions