我正在构建一个在SQL Server上使用集成安全性的winforms应用程序。现在,我执行以下操作以确保通知用户他/她无权访问某个架构(每个人都具有选择权限,但很少有人具有更新和插入权限)。
try
{
string sqlx = "select * from test.t";
SqlCommand comm = new SqlCommand(sqlx, conn);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
return;
}
catch (SqlException ex)
{
if (ex.Number == 229 | ex.Number == 230)
System.Windows.Forms.MessageBox.Show("You do not have permission to update this table. Please contact your system admin for permission.");
else
System.Windows.Forms.MessageBox.Show(ex.Message);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
Run Code Online (Sandbox Code Playgroud)
例如,除了让用户甚至没有单击删除按钮的能力之外,还有没有办法从C#中“预筛选”用户权限?