[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to add domain user to a SQL database

Posted on 2012-03-22
6
Medium Priority
?
407 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

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 2000 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 70

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

834 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