How to add domain user to a SQL database

I am looking to add domain/user from the windows domain to a SQL Database.  The only issue is that when I try to add the user, I only find code that states the following:

CREATE LOGIN [Domain\user1] FROM WINDOWS;
            USE DatabaseName CREATE USER user1 FOR LOGIN [Domain\user1]

Keep in mind that the user already exists, so how do I add a user to the database as opposed to create it?
VBBRettAsked:
Who is Participating?
 
Norman MainaCommented:
This should do it:
use database
CREATE LOGIN [DOMAIN\username] FROM Windows


In c#  all you need to execute is CREATE LOGIN [DOMAIN\username] FROM Windows in your command string.
Your connection string will reference the database.
0
 
geektothecorenjCommented:
When you say the user already exist do you mean in AD or SQL?

You go to SQL Server Management Studio then right click on security choose NEW Login from there you can search AD for the user and you can choose which Database you want them added to.
0
 
VBBRettAuthor Commented:
the user group is located in both, on the server and on AD.  I am trying to add them to the database using C# code and a SQL query but I am getting issues when trying to add the user group.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
geektothecorenjCommented:
Ah your question was under SQL Server I would add the C# tag so the programming gurus could help you.
0
 
VBBRettAuthor Commented:
The programming is not really needed, I have a handle on that.  I just need to add a user to the database
0
 
Scott PletcherSenior DBACommented:
Hmm, if the user already exists in that db, you don't have need to add it.  In this context, create and add are the same thing.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.