如何使用密码连接到sqlite数据库 [英] How to connect to sqlite database with password
问题描述
我有一个 sqlite 数据库,我想使用数据库的密码从我的 C# 程序进行连接.我正在使用 Navicat 并使用密码test"设置加密数据库文件然后通过代码我的连接字符串是:
I have a sqlite database and I want to connect from my C# program using a password for the database. I am using Navicat and I set encrypt database file with password "test" and then by code my connection string is:
_connection = new SQLiteConnection("Data Source=MedExpress.db;Version=3;Password=\"test\";");
或
_connection = new SQLiteConnection("Data Source=MedExpress.db;Version=3;Password=test;");
但这不起作用.
错误是:打开的不是数据库文件的文件文件已加密或不是数据库
我可以像这样在没有密码的情况下连接到数据库:
I can connect to the database without a password like this:
_connection = new SQLiteConnection("Data Source=MedExpress.db;Version=3;");
我的问题是如何为 sqlite 数据库设置密码并使用 System.Data.SQLite
My question is how can I set a password to a sqlite database and connect from C# program using System.Data.SQLite
推荐答案
这是带密码的连接字符串
This is the connection string with password
Data Source=filename;Version=3;Password=myPassword;
正如您所说,您使用 navicat 来设置 sqlite 加密.加密意味着您对数据库进行了加密,这与为数据库设置密码不同.
As you stated that you use navicat to set the sqlite encryption. Encryption means that you've encrypted the database it's different from setting a password to a database..
在设置数据库密码时试试这个代码..
in setting a password to a database try this code..
//create file
SQLite.SQLiteConnection.CreateFile("c:\\mydatabase file.db3")
Dim cn As New SQLite.SQLiteConnection
//set password
cn.ChangePassword("paxword")
//remove password
cn.ChangePassword("")
先删除加密..
这篇关于如何使用密码连接到sqlite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!