In C #, how to connect an encrypted SQLite database

Source: Internet
Author: User
Tags sqlite sqlite database



There are two kinds of data encryption, one is to encrypt the database itself, the other is to encrypt the data in the data table,



If the SQLite database encryption, I use a management tool here called Sqlitedeveloper, the following can be encrypted database





If you open the database without a password in the tool, you will be prompted with the following error:





or using the wrong password in C # will also give you the wrong hint:


System.Data.SQLite.SQLiteException: "File is encrypted or was not a database




The correct way to connect is to provide the correct password in the connection string:


using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OpenSqliteDBByPwd
{
    class Program
    {
        static void Main(string[] args)
        {

            string DB_PATH = "Data Source=EncryptedDB.db3; Password=1111";


            using (SQLiteConnection con = new SQLiteConnection(DB_PATH))
            {
                con.Open();
                string sqlStr = @"INSERT INTO Customer(CUST_NO,CUSTOMER)
                                  VALUES
                                  (
                                      3001,
                                      ‘Allen‘
                                  )";
                using (SQLiteCommand cmd = new SQLiteCommand(sqlStr, con))
                {
                    cmd.ExecuteNonQuery();
                }
            }
        }
    }
}





In C #, how to connect an encrypted SQLite database


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.