I distribute updates to our database in the form of backups “With Replace”, but the users can install it to any location on any hard drive, which means I need to “Exec SP_HelpFile” on it before running “Restore With Move”. But SP_HelpFile requires me to “Use TheDatabase” first, which I can’t do if it’s already stuck in a failed restore. I can’t even run “With Recovery” if I can’t tell it where to restore. Is there any way to use the Master database to get the filenames? Right now my only solution is to delete and reinstall, but I’d like the automated updater to be able to handle it on its own.
UPDATE: Server version is 2005 & 2008
You should be able to get the path+filename without having to use the database. sp_helpfile uses the local sys.sysfiles but for now at least you can use the catalog view sysaltfiles, still in master for backward compatibility reasons… this is assuming SQL Server 2005+ (please always specify the version of SQL Server you’re using):