Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 409
  • Last Modified:

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?
0
VBBRett
Asked:
VBBRett
1 Solution
 
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
 
geektothecorenjCommented:
Ah your question was under SQL Server I would add the C# tag so the programming gurus could help you.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
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
 
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
 
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.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now