Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 568
caseyboardman Avatar asked Sep 16 '26 18:09

caseyboardman


2 Answers

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.

like image 118
user53445 Avatar answered Sep 18 '26 08:09

user53445


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.

like image 32
caseyboardman Avatar answered Sep 18 '26 08:09

caseyboardman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!