Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restore With Recovery through SMO

Status
Not open for further replies.

brage98

IS-IT--Management
Sep 8, 2010
27
CA
We have the following dead-simple restore code:
Restore DATABASE MyDataBaseName with Recovery

I want to turn the above TSQL into powershell (or whatever other Programming language through SMO)

I have the following code:

Code:
$restore = new-object Microsoft.SqlServer.Management.Smo.Restore

$restore.Database         = $databaseName
$restore.ReplaceDatabase  = $replace
$restore.Action           = "Database"
$restore.NoRecovery       = $false

$server = New-Object ("Microsoft.sqlserver.management.smo.server") ("MyServer")

$restore.SqlRestore($server)
Above code gives me the following error:
"Exception calling "SqlRestore" with "1" argument(s): "Restore failed for Server [server name]"
I know if I were to do an actual restore, I would have to specify the restore file etc... but all I want is "Restore database with Recovery"...

any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top