简体   繁体   中英

sync SQL Server 2005 login passwords

Background:
We are running a web application where each user has a login to the system. The application login is mapped to an actual SQL Server 2005 login (which we needed to create). Our development and disaster recovery sites are simply copies of this setup. On a nightly basis, the production database is backed up, the dump is archived, and we restore dev and DR using this file. When this is done, we need to run sp_change_users_login for each user to remap the database user to the SQL login.

Problem:
When the user changes their password on production, the SQL login password is changed. This is not getting synced to dev/DR, so if they try to log on to one of those sites, they can't, and need to reset their password. Is there a [good] way to keep these SQL logins synced across multiple installs?

The next version of this product eliminates the SQL login need, but upgrading is not a current priority.

Script the logins with the password hashed and then drop and re-create them on your target server after you drop the database and before you restore the database back-up. That's how we script SQL2005 logins with our scripter software. You might like to try the software - www.dbghost.com - or build your own solution.

Solution:

This is a follow up to markbaekdal's answer. Here's how I did it:

I run the following against the production database:

SELECT  'ALTER LOGIN ' + CAST(name AS VARCHAR) + ' WITH PASSWORD = ', password_hash, ' HASHED;'
FROM    sys.sql_logins 
JOIN    mydatabase..mytable
ON      mycolumn = name
GO

and pipe it through "findstr ALTER" (ah, windows) to a file named loginUpdates.sql. I then run that file against the development and DR databases. It works like a charm.

If you want to get really hardcore, here's a support article a coworker of mine found: http://support.microsoft.com/kb/918992 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM