VBBRett
asked on
How to Add Users to SQL Server database
How do you add users to a SQL Server Database using C#? I want to add 5 users to a database with a domain\user format. Thanks!
ASKER
How do you give the user roles like DbOwner?
You can add roles using sp_addrolemember. See http://sqlserverplanet.com/security/add-user-to-role
ASKER
And how do you specify the domain where the user is coming from given that when I add the user domain\\user I get the following error:
I would like to add the following user:
Mycompanydomain\myuser as opposed to just myuser.
I would like to add the following user:
Mycompanydomain\myuser as opposed to just myuser.
ASKER
This is not working, especially that I am passing the query through my C# code to get this work. Please help me find a solution so I can put this to rest. I need the following written in C#
SqlCommand cmd = new SqlCommand("Create LOGIN " + usertobeadded + " USE " + databasename + " " +"CREATE USER " + usertobeadded + " FOR LOGIN " + usertobeadded " GO", conn);
I keep on getting with the '\' sign or the ';' sign. What do I do?
SqlCommand cmd = new SqlCommand("Create LOGIN " + usertobeadded + " USE " + databasename + " " +"CREATE USER " + usertobeadded + " FOR LOGIN " + usertobeadded " GO", conn);
I keep on getting with the '\' sign or the ';' sign. What do I do?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I'm not a C# developer - I code mainly in Java - but I'm guessing it might be an issue with escaping the backslash character.
http://blog.akilles.org/2008/03/12/escaping-backslash-character-in-c-net-mysql-queries/
http://blog.akilles.org/2008/03/12/escaping-backslash-character-in-c-net-mysql-queries/
http://msdn.microsoft.com/en-us/library/ms173463.aspx
delete them using DROP USER
http://msdn.microsoft.com/en-us/library/ms189438.aspx