简体   繁体   中英

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM