sqlite的无法打开数据库文件加密或不是一个数据库的C#? [英] sqlite unable to open database file is encrypted or is not a database c#?
问题描述
我工作的一个Windows应用程序.NET 2.0和SQLite数据库,我的连接字符串停留在喜欢的app.config
I am working on a windows application .net 2.0 with sqlite database, my connection string stays in app.config like
<connectionStrings>
<add name="SQLiteDB" connectionString="Data Source=|DataDirectory|database.s3db;version=3;password=mypassword;" providerName="System.Data.Sqlite"/>
</connectionStrings>
在连接字符串我已经定义密码为输入mypassword如果我删除此密码,一切运作良好但是当我使用password子句,它让我在connection.open错误()语法
In the connection string i have defined password as "mypassword" if i remove this password everything is working well but when i use password clause, it gives me error in connection.open() syntax that
File opened that is not a database file
file is encrypted or is not a database
我搜索了网,发现一些版本的问题,但我使用的版本仅3正如我在连接字符串说明我还试图消除版本= 3,但问题依旧。
I searched on net and found some version issue but i am using version 3 only as i stated in connection string i also tried removing the "version=3" but problem remains the same.
我做的这个第一次,什么是它的解决方案?
I am doing this first time, what is the solution of it?
感谢。
推荐答案
在您指定的连接字符串中的密码,和数据库已经存在,SQLite的假定数据库进行加密,并会尝试与解密说密码。如果你还没有在数据库上设置一个密码然而,这将导致文件是加密的错误,因为提供的密码不能用于解密未加密的数据库。
When you specify a password in the connection string, and the database already exists, SQLite assumes the database is encrypted and will try to decrypt it with said password. If you haven't set a password on the database yet, this will result in the "file is encrypted" error, because the supplied password can't be used to decrypt an unencrypted database.
您可以删除数据库,和SQLite将创建使用连接字符串中的密码,新的加密数据库。或者,您可以使用的ChangePassword()
方法加密现有的数据库:
You can either delete the database, and SQLite will create a new encrypted database using the password in the connection string. Or, you can encrypt your existing database using the ChangePassword()
method:
// Opens an unencrypted database
SQLiteConnection cnn = new SQLiteConnection("Data Source=c:\\test.db3");
cnn.Open();
// Encrypts the database. The connection remains valid and usable afterwards.
cnn.ChangePassword("mypassword");
参考:的加密,解密和连接到加密的数据库
这篇关于sqlite的无法打开数据库文件加密或不是一个数据库的C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!