Autofix using msforeachdb

Brenda Hernandez
Brenda Hernandez used Ask the Experts™
on
Hi All,
Trying to get a stored procedure to change a login after restoring several databases.
This is what I have
exec master..sp_msforeachdb " EXEC ?..sp_change_users_login 'Auto_Fix', 'PassLogin"'
I get an error on COUNT.  Can anyone give me a hand?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
No bites?  Some guru out there surely knows the answer to this!
Chief Technology Officer
Most Valuable Expert 2011
Commented:
See if it is just the quoting:
exec master..sp_msforeachdb 'EXEC ?..sp_change_users_login ''Auto_Fix'', ''PassLogin'''

Open in new window

Author

Commented:
BINGO!
I tried every combination of quotes I could think of, but couldn't get it right.
Script works like a charm!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial