ErikEJ / SqlCeToolbox

SQLite & SQL Server Compact Toolbox extension for Visual Studio, SSMS (and stand alone)
Other
847 stars 174 forks source link

Error opening encrypted SQLite database #929

Closed InteXX closed 2 years ago

InteXX commented 2 years ago

I'm getting an error when I attempt to connect to an encrypted SQLite database:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Data.SQLite.SEE.License, Version=1.0.114.0, Culture=neutral, PublicKeyToken=433d9874d0bb98c5' or one of its dependencies. The system cannot find the file specified.

File name: 'System.Data.SQLite.SEE.License, Version=1.0.114.0, Culture=neutral, PublicKeyToken=433d9874d0bb98c5'
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.Load(String assemblyString)
   at System.Data.SQLite.SQLiteExtra.InnerVerify(String argument)
   at System.Data.SQLite.SQLiteExtra.Verify(String argument)
   at System.Data.SQLite.SQLite3.SetPassword(Byte[] passwordBytes, Boolean asText)
   at System.Data.SQLite.SQLiteConnection.Open()
   at ErikEJ.SqlCeToolbox.Dialogs.SQLiteConnectionDialog.TestConnection(Boolean showMessage) in C:\projects\sqlcetoolbox\src\GUI\SqlCe35Toolbox\Dialogs\SQLiteConnectionDialog.xaml.cs:line 57

Steps to reproduce

  1. Create a SQLCipher-encrypted database using DB Browser for SQLite (https://sqlitebrowser.org/)
  2. Attempt to create a connection to that database
  3. Note the MessageBox that appears displaying the stack trace

Further technical details

Toolbox/Power Tools version: v4.8.735

Database engine: SQLite

Visual Studio or SSMS version: Visual Studio 2022

ErikEJ commented 2 years ago

Yes, this is no longer supported with System.Data.Sqlite, and well documented: https://sqlite.org/forum/info/ca910d2f0d4e45c8

Maybe you can use this old release of the Toolbox (not tested): https://github.com/ErikEJ/SqlCeToolbox/releases/tag/vs2012

InteXX commented 2 years ago

You're always right there with your responses. I don't know how you do it.

Perhaps you might consider including an additional package to support encryption?

The Microsoft documentation favors SQLCipher (indeed, it's the only one mentioned that has a NuGet package—and it's currently under active development). I was able to get it working under EF Core in my Blazor WASM app using a slight variation of this technique.

Brice weighs in on the issue as well, here. Granted that post is pre-EFCore, but all it takes is a substitution of Microsoft.EntityFrameworkCore.Sqlite.Core for Microsoft.Data.Sqlite.Core (when working with EF Core).

I'm unfamiliar with the internal architecture of SqlCeToolbox, but as a first guess I imagine you might be able to check for a password and use SQLCipher if one is provided and SQLite if not.

Could this work?

ErikEJ commented 2 years ago

I do not use Microsoft.Data.Sqlite at the moment, not fully featured enough.

InteXX commented 2 years ago

Microsoft.Data.Sqlite.Core

Apparently there's a significant difference.

I'm not suggesting using it exclusively. Only when encryption comes into play.

  1. Does the above package also have the aforementioned feature limitations?
  2. If so, do they eclipse the need for encryption support?
  3. If so, could the user be notified of a caveat, e.g. "You can have encryption support, but without these other features."
ErikEJ commented 2 years ago

Easy to suggest, a huge amount of work to implement and test.

InteXX commented 2 years ago

I suspected as much. Thanks for clarifying.

DB Browser for SQLite it is :-)