21

I am trying to add a new user to an SQL Server 2012 database using SQL Server Management Studio. I right-click and select 'Add User' under Security -> Users, fill out the user information, and click OK. Management Studio throws the the error message "is not a valid login or you do not have permission”.

How can I add this user?

culix
  • 581
  • 1
  • 4
  • 13
  • 2
    This question has the same error message as [this other question](http://serverfault.com/questions/119875/is-not-a-valid-login-or-you-do-not-have-permission-on-sql-server-installati), but happens during normal administration rather than during installation. It looks like there are different causes and answers, so I'm posting this as a separate question. – culix Sep 18 '14 at 13:06

3 Answers3

26

Before adding a user one must first create a login. Logins can only be created in the servers Security-folder (not in the databses Security).

So the login can be created under <server>/Security -> Right-Click -> New -> Login....

A user with the same name and settings will automatically be added to the databases selected in the User Mapping tab when creating the login.

  • If the user wasn't already created you can create it via <server>/<database>/Security -> Right-Click -> New -> User. Note that the names of the users and logins must match.
  • If you would like to manage the users settings when it was automatically added you can change them in <server>/<database>/Security/Users/<user> -> Right-Click -> Properties.
baltermia
  • 105
  • 5
culix
  • 581
  • 1
  • 4
  • 13
  • what is the meaning of "a global Login" ? – WhyWhat Oct 08 '19 at 10:18
  • 1
    I guess we'll never know... – Denny Dec 17 '20 at 13:04
  • A Login can only be created in the `/Security` directory. That is what he means with 'global Login', as it's one that can be used by all databases in the server. After creating said login you can create the user in the `//Security` directory. – baltermia May 04 '21 at 08:36
2

If you are trying to create a user under the Contained database user model (so no global login for it), you have to provide a password during creation like this:

CREATE USER user_name WITH PASSWORD = 'strong_password';
Tarnay Kálmán
  • 1,038
  • 1
  • 7
  • 19
2

This worked for me :

CREATE USER [chris23] FROM LOGIN [##MS_PolicyEventProcessingLogin##];
EXEC sp_addrolemember N'db_datareader', 'chris23';
GO
Badr Bellaj
  • 121
  • 3