Solved

How to add domain user to a SQL database

Posted on 2012-03-22
6
394 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

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:Scott Pletcher
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Master DB with Masterkey 1 40
Parse this column 6 35
how would you excute a sproc on another database on the fly 9 29
How to keep a record with the highest value 3 42
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.
In this article I will describe the Copy Database Wizard 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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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