1

I have an encrypted database using "SQLite Cipher". When I try to connect to the database using Connection string the following error message appears:

'SQL logic error Cannot use "Password" connection string property: library was not built with encryption support.'

Code With Error

Imports System.Data.SQLite
Public Class frm_projects
    Dim dtset As New SQLiteConnection("Data Source=Setting.db;Password=m;")

    Private Sub frm_projects_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            If dtset.State = ConnectionState.Closed Then
                dtset.Open()

            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Warning")
        End Try
    End Sub
End Class

Image From DB Browser sqlite Cipher

  • Are we allowed to see your code where you're creating the connection? – Hursey Jun 28 '20 at 00:31
  • Dim dtset As New SQLiteConnection("Data Source=Setting.db;Password=m;") Try If dtset.State = ConnectionState.Closed Then dtset.Open() MsgBox("Connection Success!", MsgBoxStyle.Information, "Informations") 'list_projects.Items.Add("ANa") End If Catch ex As Exception MsgBox("Failed to connect to SQLite Database", MsgBoxStyle.Information, "Warning") End Try – Moustafa Khazaal Jun 28 '20 at 00:36
  • https://imgur.com/a/6TUVKRI – Moustafa Khazaal Jun 28 '20 at 00:37
  • https://stackoverflow.com/a/41426738/10216583 –  Jun 28 '20 at 01:20
  • Please stop posting information vital to the question in comments. Apart from the fact that code is barely readable in comments even when formatted - you haven't even formatted it - no one should have to read the comments to understand the question. If you have omitted vital information from the question then edit the question and provide it. – jmcilhinney Jun 28 '20 at 03:17
  • You say *"the following message appears"* but of course it does, because your code displays it. How about you look at the actual exception that was thrown and see what message it provides? That's what's supposed to tell you what went wrong. – jmcilhinney Jun 28 '20 at 06:29
  • Thank you for the advice I am new to this community I modified the post The problem is that whenever I want to open a connection with the encrypted database I cannot access it – Moustafa Khazaal Jun 28 '20 at 08:22
  • @JQSOFT don't work – Moustafa Khazaal Jun 28 '20 at 11:38
  • 2
    Check your connection string. What is `Data Source=Setting.db` ? This should be the path of the database. Maybe you mean: `Dim dtset As New SQLiteConnection($"Data Source={My.Settings.db};Password=m;")` where `db` is a string property in your Application settings. –  Jun 28 '20 at 17:17
  • @JQSOFT Setting.db is sqlite database file in Application path directory – Moustafa Khazaal Jun 29 '20 at 06:23

2 Answers2

2

Source of the issue

I assume that the actual reason for this error is the the lack of support in "legacy CryptoAPI" since System.Data.SQLite version ~1.0.113.1.

It was done in the following commit: https://system.data.sqlite.org/index.html/info/1dd56c9fd59a10fd

What can we do?

  1. Manually Use the last NuGet version with CryptoAPI support - 1.0.112.2.

    Notice - It must be done manually - either by editing PackageReference in csproj or by editing config.packages. the reason is that older versions are unlisted (!) from the NuGet feed: NuGet feed only shows ONE version

  2. Buy perpetual source code license for SQLite Encryption Extension (SEE) which costs one time fee of 2000$ (as of Feb 2021) - purchase link

  3. Use SQLCipher - SQLCipher is an SQLite extension that provides 256 bit AES encryption of database files - GitHub source (haven't tested it myself!)

Data Sources

itsho
  • 4,640
  • 3
  • 46
  • 68
1

Change System.data.sqlite by this package Link

To set a password to an unprotected database:

Dim conn = New SQLite.SQLiteConnection(
    "Data Source=C:\yourFolder\yourDB.db3;Version=3;")
conn.Open()
conn.ChangePassword("password")
conn.Close()

To open a password-protected database:

Dim conn = New SQLite.SQLiteConnection(
    "Data Source=C:\yourFolder\yourDB.db3;Version=3;")
conn.SetPassword("password")
conn.Open()
conn.Close()

or

Dim conn = New SQLite.SQLiteConnection(
    "Data Source=C:\yourFolder\yourDB.db3;Version=3;Password=password;")
conn.Open()
conn.Close()

To remove password from a password-protected database:

Dim conn = New SQLite.SQLiteConnection(
    "Data Source=C:\yourFolder\yourDB.db3;Version=3;Password=password;")
conn.Open()
conn.ChangePassword(String.Empty)
conn.Close()

Note: The open source database manager SQLiteStudio is able to open files which were password-protected that way, as long as you choose System.Data.SQLite instead of Sqlite 3 as your database type. (Requires v 3.1.1, the current version).