Blog By Hal Hayes
Tuesday, February 06, 2007

Often, in development, we will take a backup of a database from one SQL Server to another. Perhaps we are moving a database to our development environment to do some local debugging.

Invariably, if you use a backup/restore process, you have an orphaned database "user" account that you need to map to a login. I have done this several times, but I keep forgetting the command, so I thought I would blog it so that I won't forget it, and perhaps others would benefit from this information.

Assume your database that you restored has a user, called "appUser", that is used by some application that accesses that databasde. Use the following steps to match a login account to the database user.

  1. Create a login account, if there is not one, in this case create a SQL Server login "appLogin" (In this case we are creating a database login account, not a Windows account. But it is just as easy to do the same thing with a Windows account).
  2. Execute the following command:

EXEC sp_change_users_login 'Update_One', 'appUser', 'appLogin';

GO

That's it. Pretty easy. Make sure to check the login and user to ensure that this login/user can access the database.

You can check the details out at the Microsoft SQL Server Books-On-Line for sp_change_users_login.

2/6/2007 10:28:09 AM (Eastern Standard Time, UTC-05:00) |  | SQL Server 2005#
Search
Archive
Links
Categories
Admin Login
Sign In
Blogroll
 CTO 2.0
Antonio Chagoury
Dot NET Ramblings
Brian Noyes
 New Entry
 SharePoint Resources
Lamont Harrington
 Winsmarts
Sahil Malik
Themes
Pick a theme: