系统安装,数据库区分大小写,创建视图,表,索引的权限监测大全.

 /// <summary>
        /// 检查是否可以安装驰骋BPM系统
        /// </summary>
        /// <returns></returns>
        public static bool IsCanInstall()
        {
            string sql = "";

            string errInfo = "";
            try
            {
                errInfo = " 当前用户没有[查询系统表]的权限. ";

                if (DBAccess.IsExitsObject("AA"))
                {
                    errInfo = " 当前用户没有[删除表]的权限. ";
                    sql = "DROP TABLE AA";
                    BP.DA.DBAccess.RunSQL(sql);
                }

                errInfo = " 当前用户没有[创建表]的权限. ";
                sql = "CREATE TABLE AA (OID int NOT NULL)"; //检查是否可以创建表.
                BP.DA.DBAccess.RunSQL(sql);

                errInfo = " 当前用户没有[插入数据]的权限. ";
                sql = "INSERT INTO AA (OID) VALUE(100 )";
                BP.DA.DBAccess.RunSQL(sql);

                errInfo = " 当前用户没有[update 表数据]的权限. ";
                sql = "UPDATE AA SET OID=101";
                BP.DA.DBAccess.RunSQL(sql);

                errInfo = " 当前用户没有[delete 表数据]的权限. ";
                sql = "DELETE FROM AA";
                BP.DA.DBAccess.RunSQL(sql);

                errInfo = " 当前用户没有[创建表主键]的权限. ";
                DBAccess.CreatePK("AA", "OID", SystemConfig.AppCenterDBType);

                errInfo = " 当前用户没有[创建索引]的权限. ";
                DBAccess.CreatIndex("AA", "OID"); //可否创建索引.


                errInfo = " 当前用户没有[查询数据表]的权限. ";
                sql = "select * from AA "; //检查是否有查询的权限.
                BP.DA.DBAccess.RunSQLReturnTable(sql);

                errInfo = " 当前数据库设置区分了大小写,不能对大小写敏感,如果是mysql数据库请参考 https://blog.csdn.net/ccflow/article/details/100079825 ";
                sql = "select * from aa "; //检查是否区分大小写.
                BP.DA.DBAccess.RunSQLReturnTable(sql);

                if (DBAccess.IsExitsObject("AAVIEW"))
                {
                    errInfo = " 当前用户没有[删除视图]的权限. ";
                    sql = "DROP VIEW AAVIEW";
                    BP.DA.DBAccess.RunSQL(sql);
                }

                errInfo = " 当前用户没有[创建视图]的权限.";
                sql = "CREATE VIEW AAVIEW AS SELECT * FROM AA "; //检查是否可以创建视图.
                BP.DA.DBAccess.RunSQL(sql);

                errInfo = " 当前用户没有[删除视图]的权限.";
                sql = "DROP VIEW AAVIEW"; //检查是否可以删除视图.
                BP.DA.DBAccess.RunSQL(sql);

                errInfo = " 当前用户没有[删除表]的权限.";
                sql = "DROP TABLE AA"; //检查是否可以删除表.
                BP.DA.DBAccess.RunSQL(sql);
                return true;
            }
            catch (Exception ex)
            {
                if (DBAccess.IsExitsObject("AA") == true)
                {
                    sql = "DROP TABLE AA";
                    BP.DA.DBAccess.RunSQL(sql);
                }

                if (DBAccess.IsExitsObject("AAVIEW") == true)
                {
                    sql = "DROP VIEW AAVIEW";
                    BP.DA.DBAccess.RunSQL(sql);
                }

                string info = "检查数据库安装权限出现错误:";
                info += "\t\n1. 当前登录的数据库帐号,必须有创建、删除视图或者table的权限。";
                info += "\t\n2. 必须对表有增、删、改、查的权限。 ";
                info += "\t\n3. 必须有删除创建索引主键的权限。 ";
                info += "\t\n4. 我们建议您设置当前数据库连接用户为管理员权限。 ";
                info += "\t\n ccbpm检查出来的信息如下:" + errInfo;

                info += "\t\n etc: 数据库测试异常信息:" + ex.Message;

                throw new Exception("err@" + info);
                //  return false;
            }
            return true;
        }

评论区

JFinal

2019-09-26 17:42

感谢分享

热门分享

扫码入社