I am trying to insert users into a SQL database, but not the way you are thinking.
Usually, in SQL Management Studio, one would enter new users through the Security - Logins wizard. But How can one do this in a C# Winform?
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 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:
SqlConnection //the rest of the code follows here
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.