Exemplo n.º 1
0
        /// <summary>
        /// 创建一个新的数据库
        /// </summary>
        /// <param name="database"></param>
        /// <param name="description"></param>
        /// <returns></returns>
        public override bool CreateDatabase(string database, ref string description)
        {
            description = "";
            if (!VaildStringParameters(ref description, database))
            {
                return(false);
            }

            database = database.Trim();
            if (!database.StartsWith("[", StringComparison.Ordinal) || !database.EndsWith("]", StringComparison.Ordinal))
            {
                database = "[" + database + "]";
            }

            if (!Open(ref description))
            {
                description = "数据库打开出错!";
                return(false);
            }

            DatabaseFactory.MSSQL mssql = new DatabaseFactory.MSSQL(this.ConnectionString);
            int result = mssql.ExecuteNonQuery("create database " + database + ";");

            Close();

            //测试证明-1已经创建成功了
            if (result < -1)
            {
                description = "数据库指令执行发生错误1,返回值是 " + result.ToString() + "|" + "create database " + database + "|" + this.ConnectionString;

                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 修改用户密码
        /// </summary>
        /// <param name="user"></param>
        /// <param name="oldPassword"></param>
        /// <param name="newPassword"></param>
        /// <param name="description"></param>
        /// <returns></returns>
        public override bool EditUserPassword(string user, string oldPassword, string newPassword, ref string description)
        {
            description = "";
            if (!VaildStringParameters(ref description, user, oldPassword, newPassword))
            {
                return(false);
            }

            if (!Open(ref description))
            {
                return(false);
            }
            string sql = string.Format("exec sp_password '{0}', '{1}', '{2}';",
                                       (string.IsNullOrEmpty(oldPassword) ? "NULL" : oldPassword), newPassword, user);

            DatabaseFactory.MSSQL mssql = new DatabaseFactory.MSSQL(this.ConnectionString);

            //int result =Shove . Database.MSSQL.ExecuteNonQuery((SqlConnection)this.conn,
            //    string.Format("exec sp_password '{0}', '{1}', '{2}'",
            //    (string.IsNullOrEmpty(oldPassword) ? "NULL" : oldPassword), newPassword, user));

            int result = mssql.ExecuteNonQuery(sql);

            if (result < -1)//-1时已经成功
            {
                description = "数据库指令执行发生错误3,返回值是 " + result.ToString() + "||" + sql;

                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 物理移除数据库
        /// </summary>
        /// <param name="database"></param>
        /// <param name="user"></param>
        /// <param name="description"></param>
        /// <returns></returns>
        public override bool RemoveDatabase(string database, string user, ref string description)
        {
            description = "";
            if (!VaildStringParameters(ref description, database, user))
            {
                return(false);
            }

            database = database.Trim();
            if (!database.StartsWith("[", StringComparison.Ordinal) || !database.EndsWith("]", StringComparison.Ordinal))
            {
                database = "[" + database + "]";
            }

            if (!Open(ref description))
            {
                return(false);
            }

            string sql = string.Format(@"use {0} 
                                            EXEC sp_revokedbaccess N'{1}'
                                            EXEC sp_droplogin N'{2}' 
                                         use master
                                            ALTER DATABASE {3} SET SINGLE_USER with ROLLBACK IMMEDIATE
                                            DROP DATABASE {4}", database, user, user, database, database);

            DatabaseFactory.MSSQL mssql = new DatabaseFactory.MSSQL(this.ConnectionString);
            int result = mssql.ExecuteNonQuery(sql);

            Close();

            if (result < 0)
            {
                description = "移除数据库出现错误,返回值是 " + result.ToString();

                return(false);
            }

            return(true);
        }