在运行时设置表的密码 [英] Setting Password for a table at Runtime

查看:96
本文介绍了在运行时设置表的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

在一个程序中,我需要在运行时创建一个表并将其添加到数据库中.我知道如何使用创建表命令"为其定义一些字段(如以下代码所示),但是我需要知道的是如何在运行时为表设置密码.我的意思是,当有人要打开表时,系统会要求他(或她)密码,并且在不知道我在运行时为它设置的密码的情况下,他或她将无法打开表.请你帮助我好吗?

非常感谢

Hello,

In a program, I need to create and add a table to a database at Runtime. I know how to define some fields for it by using Create Table Command (as in following code), but what I need to know is how to set a password for the table at runtime. I mean, when ones wants to open the table, he or she would be asked for password and would not be allowed to open it readily not knowing the password I set for it at runtime. Could you please help me?

Thanks a lot

...
myCommand.CommandText = "CREATE TABLE myTable " +
                                          " (" +
                                            " ID int IDENTITY(1,1) PRIMARY KEY," +
                                            " Name char(10),"+
                                            "Age Number" +
                                            ")";

推荐答案

我可以想到两个单独的解决方案,以便按照您描述的方式进行.
第一种方法是在SQL Server中需要两个单独的登录用户帐户.第一个帐户将是实际的连接服务登录,第二个帐户将是访问表所需的连接.简而言之,您需要2个数据库连接才能打开PER USER ...
不,谢谢!-因此,我什至不打算进一步描述该方法.


第二种方法是在通过以下脚本创建表后立即锁定该表.
I can think of two seperate solutions in order to make this work in the way you described.
The first method you''ll need two seperate login user accounts in SQL Server. The first account will be the actual connection service log-in and the second account will be the connection required to access the table. So in short you''ll need 2 database connections open PER USER...
NO THANKS! - So I''m not even going to describe that method further.


The second method would be lock-down the table just as soon as its created via the following script.
DENY SELECT ON dbo.[myTable] TO useraccount;
DENY INSERT ON dbo.[myTable] TO useraccount;
DENY UPDATE ON dbo.[myTable] TO useraccount;
DENY DELETE ON dbo.[myTable] TO useraccount;
DENY ALTER ON dbo.[myTable] TO useraccount;
DENY VIEW DEFINITION ON dbo.[myTable] TO useraccount;


之后,您将让程序代码管理和验证密码.
密码验证后,您只需运行与上述相同的脚本,仅将DENY更改为GRANT,如下所示.


Afterwards you would have your code of the program manage and validate the password.
When the password validates you simply run the same script as above only changing DENY to GRANT as illustrated below.

GRANT SELECT ON dbo.[myTable] TO useraccount;
GRANT INSERT ON dbo.[myTable] TO useraccount;
GRANT UPDATE ON dbo.[myTable] TO useraccount;
GRANT DELETE ON dbo.[myTable] TO useraccount;
GRANT ALTER ON dbo.[myTable] TO useraccount;
GRANT VIEW DEFINITION ON dbo.[myTable] TO useraccount;


希望这会有所帮助,
-ArtificerGM


Hope this helps,
-ArtificerGM


这篇关于在运行时设置表的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆