sqlite无法打开数据库文件是加密的还是不是数据库? [英] sqlite unable to open database file is encrypted or is not a database?

查看:287
本文介绍了sqlite无法打开数据库文件是加密的还是不是数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有sqlite数据库的Windows应用程序.net 2.0,我的连接字符串仍位于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,如果我删除此密码,则一切正常但是,当我使用密码子句时,它给了我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,我也尝试删除了 version = 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无法打开数据库文件是加密的还是不是数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆