本文介绍了在.NET4中无法加密/解密SQLite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 7 x64上运行Visual Studio 2010。我正在写的应用程序应该在所有平台(AnyCPU)上运行。如果我使用System.Data.SQLite.dll x86版本(sqlite-netFx40-static-binary-bundle-Win32-2010-1.0.77.0.zip)或x64,我可以加密/解密数据库文件一个(sqlite-netFx40-static-binary-bundle-x64-2010-1.0.77.0.zip)。



我需要我的应用程序在两个平台上运行x86和x64 (任何CPU项目构建设置)。我试过安装ADO.NET 4.0提供程序(SQLite-1.0.67.1-vs2010-net4-setup.exe)。我添加了参考(右键单击项目,添加参考,.NET选项卡 - > System.Data.SQLite)并运行该程序。如果我解密该文件并尝试通过调用ChangePassword(myPass)加密,我得到以下异常:



此外,我尝试使用SQLiteConnection对象打开一个连接,并在两种不同的情况下得到两个不同的异常。
首先,如果文件被加密,并且我没有在连接字符串中指定密码,我得到这个:

其次,如果我添加了密码参数到连接字符串,我得到像上面那样的System.EntryPointNotFoundException。



所以,有人知道在AnyCPU平台上的C#应用​​程序中使用加密SQLite数据库的确切的方式吗?



感谢提前!

解决方案

以下解决方案有点脏,但可能会工作,我们没有使用加密数据库,如果这将为您工作不是100%。
我们下载了x64和x86的两个版本的sqlite dll,并将它们放在不同的文件夹中。我们手动加载它们,取决于当前正在运行的平台应用程序(我们检查IntPtr.Size,从.net 4在Environment类中有一个属性称为Is64BitOperatingSystem)当我们手动加载程序集时,我们获取连接实例与

  var sqliteConnectionType = assembly.GetType(System.Data.SQLite.SQLiteConnection); 
(DbConnection)Activator.CreateInstance(sqliteConnectionType);

我们不会在我们的项目中使用任何版本的sqlite。


I am running Visual Studio 2010 on a Windows 7 x64. The app I'm writing is supposed to run on all platforms (AnyCPU). I'm able to encrypt/decrypt the database file if I'm using the System.Data.SQLite.dll either x86 version (sqlite-netFx40-static-binary-bundle-Win32-2010-1.0.77.0.zip) or x64 one (sqlite-netFx40-static-binary-bundle-x64-2010-1.0.77.0.zip).

I need my app to run on both platforms x86 and x64 (Any CPU project build setting). I've tried installing the ADO.NET 4.0 Provider (SQLite-1.0.67.1-vs2010-net4-setup.exe). I added the reference (right-click on project, Add Reference, .NET tab -> System.Data.SQLite) and ran the program. If I decrypt the file and try to encrypt by calling ChangePassword("myPass"), I get the following exception:

Also, I've tried to open a connection using the SQLiteConnection object and I get two different exceptions in two different cases.First, if the file is encrypted and I don't specify a password in the connection string I get this:

Second, if I add the password parameter to the connection string, I get the System.EntryPointNotFoundException like the one above.

So, does anyone know a sure-fire way to work with encrypted SQLite database in a C# app on AnyCPU platform?

Thanks in advance!

解决方案

Following Solution is a little bit dirty, but it may work, we didn't use encrypted database so i'm not 100% if that will work for you.We downloaded both versions of sqlite dlls for x64 and x86 and placed them in different folders. We load them manually dependent on what platform application is currently running ( we check IntPtr.Size , from .net 4 there is a property in Environment class called Is64BitOperatingSystem) when we loaded assembly manually we get connection instance with

 var sqliteConnectionType = assembly.GetType("System.Data.SQLite.SQLiteConnection");
 (DbConnection)Activator.CreateInstance(sqliteConnectionType);

we don't use reference to any version of sqlite in our project.

这篇关于在.NET4中无法加密/解密SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:59