[英]How to add users to a SQL Server database in a C# Winform
I am trying to insert users into a SQL Server database, but not the way you are thinking. 我正在尝试将用户插入SQL Server数据库,而不是您所想的方式。
Usually, in SQL Server Management Studio, one would enter new users through the Security - Logins wizard. 通常,在SQL Server Management Studio中,可以通过“安全性-登录”向导输入新用户。 But how can one do this in a C# Winform application?
但是,如何在C#Winform应用程序中做到这一点呢?
Basically, my Winform would have various fields to capture, but the important ones are the username field and all the selected roles 基本上,我的Winform将具有多个要捕获的字段,但重要的是用户名字段和所有选定的角色
In this form, once a users clicks Add, the data will be stored into a separate SQL Server table. 在这种形式下,用户单击添加后,数据将存储到单独的SQL Server表中。 I would like to add the user to the database credentials
我想将用户添加到数据库凭据中
Once they have been added to the security credentials, they have the default data: 将它们添加到安全凭证后,它们将具有默认数据:
Is this possible to do via C# Winforms? 通过C#Winforms可以做到吗? Would this be possible using a dataset?
使用数据集可以吗? Would this be conventional C# code ie.
这是常规的C#代码吗?
SqlConnection //the rest of the code follows here
SqlConnection //其他代码如下
or would there have to be a new interface/form to utilise? 还是必须要使用新的界面/表格?
If you use SSMS, and right click on any object (including logins, users, etc), you can choose options to see the generation script: 如果使用SSMS,然后右键单击任何对象(包括登录名,用户等),则可以选择以下选项来查看生成脚本:
This will show you what commands you need to execute to create that object. 这将向您显示创建该对象需要执行哪些命令。 Remember that you need both the login (to the server) and user (to the database) entries.
请记住,您既需要登录名(登录到服务器),也需要用户名(登录到数据库)。 So: just issue equivalent commands!
因此:只需发出等效命令! For some things like passwords, you many need to consult the
CREATE LOGIN
etc documentation, since the server is unable to script those out. 对于诸如密码之类的事情,由于服务器无法通过脚本编写出来,因此您需要查阅
CREATE LOGIN
等文档。 Note that this does mean your application needs to run with enough access to manage users. 请注意,这确实意味着您的应用程序需要具有足够的访问权限才能运行以管理用户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.