Home > Backend Development > C#.Net Tutorial > Example sharing of how to connect to an encrypted database (Sqlite) in C#

Example sharing of how to connect to an encrypted database (Sqlite) in C#

黄舟
Release: 2017-08-07 13:08:23
Original
2767 people have browsed it

There are two types of data encryption, one is to encrypt the database itself, and the other is to encrypt the data in the data table. This article will introduce you to the C# method of connecting to the encrypted Sqlite database. If you are interested, Friends, let’s take a look.

There are two types of data encryption. One is to encrypt the database itself, and the other is to encrypt the data in the data table.

If the SQLite database is encrypted , a management tool I use here is called SQLiteDeveloper, you can encrypt the database as follows

,

If you open the database without providing a password in the tool , will give you the error message as follows:

,

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

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

,

The correct connection method is to provide it in the connection string Correct password:


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();
        }
      }
    }
  }
}
Copy after login

Summary

The above is the detailed content of Example sharing of how to connect to an encrypted database (Sqlite) in C#. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template