MDV2000
MDV2000

Reputation: 812

System.Data.SQLite in UNMANAGED C++

I want to use SQLite as a database for my C++ project. I also need the ability to password protect the database. I got the standard SQLite from SQLite.org working - but I need to password/encrypt the database and they don't do that - they just stub the interface for it to be done with

SQLITE_API int sqlite3_key( sqlite3 *db, const void *pKey, int nKey);

After researching on the web how to do this, I came across System.Data.SQLite. It claims to do all I need quite easily, but I need to do it from unmanaged C++ project in Visual Studio 2008. I tried their project - but I can't get my unmanaged C++ project to allow the DLL to work - it squawks about dll not being safe/clr:safe compile - which I can't set in the System.Data.SQLite project and compile.

Can anyone help me with this or point me to a good resource on how to do this? I have been thrown into a C++ project (hadn't touched C/C++ since college (97-98), so I am really struggling with this when it comes to the linker/libs/modules. Java and .NET have spoiled me!

Thanks, Mike

Upvotes: 0

Views: 876

Answers (2)

Nguyen Duy Anh
Nguyen Duy Anh

Reputation: 11

Recently, I've faced a similar problem like Mike and resolved it. I would like to post my solution here in case anyone need.

I have two programs:

One is in C# to create encrypted sqlite database files using System.Data.SQLite.

The other one is in C++ to read the file created by the C# program.

After googling with no result, I looked at source code of System.Data.SQLite to figured out how System.Data.SQLite encrypts a database file. I recognized that System.Data.SQLite uses SQLite.Interop.dll wrapping native sqlite with additional features such as encryption. Therefore I used that native source code to build a static library. Then I use the library to read the encrypted database files.

You can find the source code at the following link:
https://github.com/OpenDataSpace/System.Data.SQLite/tree/master/SQLite.Interop/src

Update 2020/04/11
You can find a step by step guide at the following link:
https://wordpress.com/post/nguyenduyanhsite.wordpress.com/71

Upvotes: 1

ssube
ssube

Reputation: 48277

You can't use a managed DLL from unmanaged code like that, they're different systems. Just use the normal unmanaged SQLite build and read the docs on how to use keys.

Upvotes: 1

Related Questions