数据库应用程序角色配置

1、添加角色
exec sp_addapprole 'denlu','123456'
帐号:denlu 密码:123456
2、查看角色是否存在
exec sp_setapprole 'denlu','123456'
3、更改角色密码和架构
alter application role [myapprole]
with name=[denlu] ,
password='234567' ,
DEFAULT_SCH EMA = [dbo]

3、配置解色权限
在角色可操作的表中鼠标选择表点右建属性=》权限
在打开的窗体搜索角色,点搜索出来用户和角色的搜索窗,对象类型选择应用角色,点击下方的浏览选择角色如“denlu”
选择确定以后在属性窗里用户和角色栏里就多了一个"denlu"角色,选择角色在它对应的下方权限设置权限,配置就完成了
4、使用
例:C#
    public class getconnection
    {
        private System.Data.SqlClient.SqlConnection mypunconnection;
        public getconnection(string csstring, string awe, string olk)
        {
            System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(csstring);
            System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("sp_setapprole", connection);
            try
            {
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.Parameters.Clear();
                command.Parameters.Add("@rolename", System.Data.SqlDbType.NVarChar).Value = awe;
                command.Parameters.Add("@password", System.Data.SqlDbType.NVarChar).Value = olk;
                connection.Open();
                command.ExecuteNonQuery();
                this.mypunconnection = connection;
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                command.Dispose();
                connection.Close();
                System.Data.SqlClient.SqlConnection.ClearPool(connection);
                connection.Dispose();
            }
        }
        public System.Data.SqlClient.SqlConnection connection
        {
            get
            {
                return this.mypunconnection;
            }
        }
        public void Dispose()
        {
            if (this.mypunconnection != null)
            {
                this.mypunconnection.Close();
                System.Data.SqlClient.SqlConnection.ClearPool(this.mypunconnection);
                this.mypunconnection.Dispose();
            }
        }
    }
    public class usertity
    {
        public string getuser()
        {
            getconnection myconn = null;
            myconn = new getconnection(System.Configuration.ConfigurationManager.ConnectionStrings["maindatabase"].ConnectionString, "denlu", "123456");
            System.Data.SqlClient.SqlTransaction transa = myconn.connection.BeginTransaction();
            System.Data.SqlClient.SqlCommand myCommand = new System.Data.SqlClient.SqlCommand();
            try
            {
                //检查字符串合理性
                myCommand.CommandText = "select top 1 id from user where userid =11";
                Object myo = myCommand.ExecuteScalar();
            }
            catch (Exception e)
            {
            }
            finally
            {
                myconn.Dispose();
            }
            return "";
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值