2

I have a development machine with a new database I have designed. The server has a login L1 and the database has a user U1. L1 is mapped to M1 and tables have permissions set up for U1. Authentication is SQL Server authentication. I wanted to fully backup the database and restore to the production server so that I could start to use it in production.

I had a problem with user U1: I could not map it to any login on the production server. So I could not use U1 with any login. Is this correct behavior?

András Váczi
31.8k13 gold badges103 silver badges152 bronze badges
asked Aug 29, 2013 at 7:50
3
  • 'I could not map it to any login' - why? Is there a login user missing or what? Commented Aug 29, 2013 at 8:18
  • Well the restored database on the production server has a user U1 and tables have permissions set for this user. But I cant map a login to this user OR I don't know how to. Commented Aug 29, 2013 at 8:38
  • use DB ALTER USER U1 WITH NAME = U1 , LOGIN = L1 Commented Aug 29, 2013 at 14:28

1 Answer 1

1

You have to create a login on the prod server as when you restore the backup to PROD server, you are having an orphaned user.

So steps are :

  • Create Login using SID option (if you are just having 1 login to map). Else use sp_help_revlogin
  • You can use SID from sys.database_principals where type_desc = SQL_USER (since you mentioned you are using SQL Login).
  • Then run ALTER USER as below :

    USE [DatabaseName]
    go
    ALTER USER [UserName]
    WITH LOGIN = [UserName]
    

Note: sp_change_users_login is deprecated.

answered Aug 29, 2013 at 14:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.