Solved

How to add domain user to a SQL database

Posted on 2012-03-22
6
386 Views
Last Modified: 2012-03-23
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
Comment
Question by:VBBRett
6 Comments
 
LVL 3

Expert Comment

by:geektothecorenj
ID: 37753816
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
 

Author Comment

by:VBBRett
ID: 37753829
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
 
LVL 3

Expert Comment

by:geektothecorenj
ID: 37753835
Ah your question was under SQL Server I would add the C# tag so the programming gurus could help you.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:VBBRett
ID: 37753905
The programming is not really needed, I have a handle on that.  I just need to add a user to the database
0
 
LVL 12

Accepted Solution

by:
NormanMaina earned 500 total points
ID: 37753910
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
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 37754646
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

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now