patternsqlMinor
Map a Login to a User that was Created Without Mapping to a Login
Viewed 0 times
mapwithoutcreateduserloginthatwasmapping
Problem
This question has been asked before, but I didn't see any answer.
How does one map a SQL-Instance
when the user was originally created using the "SQL User without login" User Type option in the GUI?
I'm using SQL Server 2012.
How does one map a SQL-Instance
Login to a Database User,when the user was originally created using the "SQL User without login" User Type option in the GUI?
I'm using SQL Server 2012.
Solution
By selecting SQL user without login within SSMS'
If you were to create a login and attempt to alter the user with the new login, like the following attempt:
You will get the following error:
Msg 33016, Level 16, State 1, Line 8
The user cannot be remapped to a login.
Remapping can only be done for users that were mapped to Windows or SQL logins.
Because of that, I don't think you can link up a login to this type of user without recreating it.
It should be relatively painless, as you could just script out the user, but change the parameters from
EDIT: As pointed out by Aaron below, ensure that you're taking note of permissions and role memberships before making any changes. You'll want to ensure that you can get back to the permissions state you currently are in, if that's the desired behavior.
Create User dialog, this is the T-SQL that is generated (with no other options besides the user name supplied):USE [AdventureWorks2012]
GO
CREATE USER [User1] WITHOUT LOGINIf you were to create a login and attempt to alter the user with the new login, like the following attempt:
CREATE LOGIN TestLogin1
WITH PASSWORD = 'p@$w0rd';
GO
USE AdventureWorks2012;
GO
ALTER USER User1
WITH LOGIN = TestLogin1;You will get the following error:
Msg 33016, Level 16, State 1, Line 8
The user cannot be remapped to a login.
Remapping can only be done for users that were mapped to Windows or SQL logins.
Because of that, I don't think you can link up a login to this type of user without recreating it.
It should be relatively painless, as you could just script out the user, but change the parameters from
WITHOUT LOGIN to whatever login you want it to be mapped to.EDIT: As pointed out by Aaron below, ensure that you're taking note of permissions and role memberships before making any changes. You'll want to ensure that you can get back to the permissions state you currently are in, if that's the desired behavior.
Code Snippets
USE [AdventureWorks2012]
GO
CREATE USER [User1] WITHOUT LOGINCREATE LOGIN TestLogin1
WITH PASSWORD = 'p@$$w0rd';
GO
USE AdventureWorks2012;
GO
ALTER USER User1
WITH LOGIN = TestLogin1;Context
StackExchange Database Administrators Q#68924, answer score: 7
Revisions (0)
No revisions yet.