在运行时设置表的密码

编程入门 行业动态 更新时间:2024-10-25 08:22:23
本文介绍了在运行时设置表的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

更多推荐

在运行时设置表的密码

本文发布于:2023-06-10 22:51:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/620781.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:密码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!