2

I am handling a Unity project using SQLite. When I open an encrypted database, the following error message shows up:

EntryPointNotFoundException: sqlite3_key Mono.Data.Sqlite.SQLite3.SetPassword (System.Byte[] passwordBytes) Mono.Data.Sqlite.SqliteConnection.Open () SQLiteHandler.Start () (at Assets/Script/SQLiteHandler.cs:18)

Here is my connection code, neither putting the password into connection string nor using SetPassword work.

connString = string.Format("Data Source={0};Version=3;Password=testing123",Application.dataPath+"/demodb.db");
using (conn = new SqliteConnection (connString)) {
    conn.Open ();
    //do something
    conn.Close ();
}
7
  • A few things: 1. Are you sure you have the right version? 2. I see a few problems here that I'll assume are mistakes you made for your example and don't exist in your actual code, such as you never declare conn. Commented May 12, 2017 at 15:02
  • 1. How can I check the version? 2. Yes, conn has been well declared, here is just a portion of my code. Commented May 12, 2017 at 16:03
  • Checked. The used version is 3.18 Commented May 13, 2017 at 13:04
  • Are you using Mono? Commented May 13, 2017 at 14:52
  • @Sty yes. MonoDevelop-Unity Commented May 13, 2017 at 16:41

2 Answers 2

1

Mono.Data.Sqlite does not support password protection, it does not include the two critical entry points sqlite3_key and sqlite3_rekey. So, better look for other extensions or libraries.

Here is a useful Unity package SqlCipher4Unity which fits well with password protection.

Sign up to request clarification or add additional context in comments.

Comments

0

You have to use SetPassword() when you create the Database initially (or at least before it is opened) - for example:

SQLiteConnection.CreateFile(DataPath + "/SomeDb.sqlite");
SQLiteConnection cnn = new SQLiteConnection("Data Source=" + DataPath + "/SomeDb.sqlite");
cnn.SetPassword("testing123!");

Then you can use the password in the connection string to access the database - for example:

 var ConnectionString = "Data Source=" + DataPath + "/SomeDb.sqlite;Password=testing123!;"; 

Hopefully that will help you out.

5 Comments

Thanks for your comment! The database file is already created but cannot get access with a password. I can access it if the database hasn't setup password protection, so I don't think it is a db file problem but an implementation problem.
I believe Password protection is only available in Version 3 - you are specifically saying Version=3 in the connection string, but is the SQLite file version 3? Are you creating the file yourself in the code, or getting it from elsewhere?
This is an old thread, but there's a discussion on the Unity site which might be worth a try: Unity3D Forum
How can I ensure its version? I am sure the file location is correct.
Ha! Great minds - I've noticed in other comments you've got the version so that's good - I'm afraid I've used SQLite a fair bit but not with Mono, so may have to leave you in the hands of experts! If you get an answer though be sure to post it, you've got me intrigued...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.