Mono.Data.Sqlite.SqliteConnection.SetPassword C# (CSharp) Method

SetPassword() public method

Sets the password for a password-protected database. A password-protected database is unusable for any operation until the password has been set.
public SetPassword ( byte databasePassword ) : void
databasePassword byte The password for the database
return void
    public void SetPassword(byte[] databasePassword)
    {
      if (_connectionState != ConnectionState.Closed)
        throw new InvalidOperationException("Password can only be set before the database is opened.");

      if (databasePassword != null)
        if (databasePassword.Length == 0) databasePassword = null;

      _password = databasePassword;
    }

Same methods

SqliteConnection::SetPassword ( string databasePassword ) : void

Usage Example

示例#1
0
 public void CreateDataBase(string dbPath, string pwd)
 {
     if (!File.Exists(dbPath))
     {
         SqliteConnection.CreateFile(dbPath);
         if (string.IsNullOrEmpty(pwd))
         {
             using (SqliteConnection conn = new SqliteConnection("Data Source=" + dbPath))
             {
                 try
                 {
                     conn.SetPassword(pwd);
                 }
                 catch
                 {
                     conn.Close();
                     throw;
                 }
                 finally
                 {
                     conn.Close();
                 }
             }
         }
     }
     else
         throw new Exception("已经存在名叫:" + dbPath + "的数据库!");
 }
All Usage Examples Of Mono.Data.Sqlite.SqliteConnection::SetPassword