Use SQLCMD to Restore Sql Database - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

zead
Posts: 5
Joined: Thu Mar 28, 2013 9:09 am

Use SQLCMD to Restore Sql Database

Hi,

We are use custome action to restore sql database and we put the sqlcmd
Command as the following:
SQLCMD -E -S .\sqlexpress_2 -i RestoreMasterDB.sql -v mPath=[TempFolder]
[TempFolder] is the temporary folder in the windows volume that contains the MasterDB.Bak

And We us the sql script file to run the restore script which contains the following script:
RESTORE DATABASE MasterDB
FROM DISK = '$(mPath)\MasterDB.bak'
WITH MOVE 'SecurityDB' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS_2\MSSQL\DATA\MasterDB.mdf',
MOVE 'SecurityDB_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS_2\MSSQL\DATA\MasterDB_log.ldf'

But the following error message shown
“{SQL_ERROR}: {SQL_STATE: 42000} Cannot open backup device c:\Program Files\
Microsoft SQL Server\MSSQL10.SQLEXPRESS_2\MSSQL\Backup\$(mPath)\MasterDB.Bak
Operating System Error 3 (failed to retrieve text for this error. Reason: 15105).”

See the attached image for more info.

Please help me to solve this issue.
Thanks
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Use SQLCMD to Restore Sql Database

Hello,

Please take a look on our "Use a property in a SQL script" article which can be useful for you.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”