Restore with dynamic fields

Compresses, encrypts, secures and monitors SQL Server backups.

Moderators: JonathanWatts, Chris Auckland, eddie davis, Colin Millerchip, Brian Harris, james.billings, RBA, petey

Restore with dynamic fields

Postby jonstahura » Fri Oct 19, 2012 8:14 pm

Hi.. I don't know if anyone has done this, but I have quite a few databases I would like to restore automatically. I have a vb.net program passing variables to a stored procedure and would like the sql backup 7 to use those in the restore command... something like below:

EXECUTE master..sqlbackup '-SQL "RESTORE DATABASE [@sitename + ''_APP_'' + @DBSUFFIX]
FROM DISK = @backupfilepath WITH MOVE DATAFILES TO @dbdirectory,
MOVE LOGFILES TO @tlogdirectory, REPLACE " '
jonstahura
 
Posts: 13
Joined: Fri Sep 28, 2012 2:28 pm

Postby Brian Donahue » Mon Oct 22, 2012 4:25 pm

Thanks for your question. It's not something that we support directly, but the .NET Framework does have a SqlClient namespace that you can use to run queries. To do what you want to in your example, I think it's best to use a parameterized query as in this example: http://www.dotnetperls.com/sqlparameter
Brian Donahue
 
Posts: 6670
Joined: Mon Aug 23, 2004 10:48 am

Postby jonstahura » Mon Oct 22, 2012 5:31 pm

thanks for the link.. i figured it out.

I needed more single quotes... a LOT more.... and then it worked! :)
jonstahura
 
Posts: 13
Joined: Fri Sep 28, 2012 2:28 pm

Postby Brian Donahue » Tue Oct 23, 2012 8:50 am

Thanks, I'm glad that worked.
Brian Donahue
 
Posts: 6670
Joined: Mon Aug 23, 2004 10:48 am


Return to SQL Backup 7

Who is online

Users browsing this forum: No registered users and 0 guests