Reputation: 580
I am trying to insert users into a SQL Server database, but not the way you are thinking.
Usually, in SQL Server Management Studio, one would enter new users through the Security - Logins wizard. But how can one do this in a C# Winform application?
Basically, my Winform would have various fields to capture, but the important ones are the username field and all the selected roles
In this form, once a users clicks Add, the data will be stored into a separate SQL Server table. 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? Would this be possible using a dataset? Would this be conventional C# code ie.
SqlConnection //the rest of the code follows here
or would there have to be a new interface/form to utilise?
Upvotes: 3
Views: 2694
Reputation: 1062865
If you use SSMS, and right click on any object (including logins, users, etc), you can choose options to see the generation script:
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. Note that this does mean your application needs to run with enough access to manage users.
Upvotes: 4