public static void SetSQLiteDBpwdByConn(string connStr, string pwd) { System.Data.SQLite.SQLiteConnection connection = new System.Data.SQLite.SQLiteConnection(connStr); connection.Open(); connection.ChangePassword(pwd); connection.Close(); }
public static void SetSQLiteDBpwd(string absPath, string pwd) { string connStr = string.Format("Data Source={0};", absPath); System.Data.SQLite.SQLiteConnection connection = new System.Data.SQLite.SQLiteConnection(connStr); connection.Open(); connection.ChangePassword(pwd); connection.Close(); }
private static void ChangePassword() { if (m_dbConnection != null && m_dbConnection.State != System.Data.ConnectionState.Open) { throw new Exception("SQLite Connection Not Open"); } m_dbConnection.ChangePassword("NewP@55w0rD"); }
/// <summary> /// 修改密码 /// </summary> /// <param name="DbFilePath"></param> /// <param name="newPassword"></param> /// <param name="OriginalPassword"></param> /// <param name="InnerPassword"></param> private void ChangePassword(string DbFilePath, string newPassword, string OriginalPassword, string InnerPassword) { System.Data.SQLite.SQLiteConnection _con = new System.Data.SQLite.SQLiteConnection(); _con.ConnectionString = "Data Source=" + DbFilePath; if (OriginalPassword.Length > 0) { _con.ConnectionString += ";Password="******"Connect database failed! :" + ex.Message); } try { System.Data.Common.DbCommand comm = _con.CreateCommand(); comm.CommandText = "update tb_admin set Password = @Password where adminId = 1"; comm.CommandType = System.Data.CommandType.Text; comm.Parameters.Add(new System.Data.SQLite.SQLiteParameter("@Password", InnerPassword)); int result = comm.ExecuteNonQuery(); if (result == 0) { throw new Exception(); } } catch (Exception ex) { throw new Exception("Change admin password failed! :" + ex.Message); } // //先修改内部密码 try { _con.ChangePassword(newPassword); } catch (Exception ex) { throw new Exception("Encruption database failed!" + ex.Message); } _con.Close(); }
public static void CreateSQLiteDB(string absPath, string pwd) { if (File.Exists(absPath)) { throw new Exception("要创建的数据库文件已存在,请核对:" + absPath); } System.Data.SQLite.SQLiteConnection.CreateFile(absPath); if (!string.IsNullOrWhiteSpace(pwd)) { string connStr = string.Format("Data Source={0};", absPath); System.Data.SQLite.SQLiteConnection connection = new System.Data.SQLite.SQLiteConnection(connStr); connection.Open(); connection.ChangePassword(pwd); connection.Close(); } }