Note that there are some explanatory texts on larger screens.

plurals
  1. POC# SMO backup of remote database to local machine
    text
    copied!<p>I have an application which performs backups and restores of SQL databases, this works fine on the local machine, however if I run this against a SQL server hosted on another machine I get the following error</p> <blockquote> <p>Microsoft.SqlServer.Management.Smo.FailedOperationException: Backup failed for Server '25.98.30.79'. ---> Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException: Cannot open backup device 'C:\Program Files\State Manager\Archive\Capture\20100217152147*product*\databases*database**database*.bak'. Operating system error 3(The system cannot find the path specified.).</p> </blockquote> <p>This appears to be being caused by the SQL server attempting to write this file to its local drive. I cannot setup a shared area into which the backup can be placed due to security restrictions.</p> <p>Does anyone know how I can move this data back to the machine the code is being called from?</p> <p>My code is below.</p> <pre><code> private string Name; private string Server; private string dbName; private string user; private string password; public Boolean performCapture(String archiveDir) { String destination = archiveDir + "\\" + Name; if (!System.IO.Directory.Exists(destination)) { System.IO.Directory.CreateDirectory(destination); } Server sqlServer = connect(); if (sqlServer != null) { DatabaseCollection dbc = sqlServer.Databases; if (dbc.Contains(dbName)) { Backup bkpDatabase = new Backup(); bkpDatabase.Action = BackupActionType.Database; bkpDatabase.Database = dbName; BackupDeviceItem bkpDevice = new BackupDeviceItem(destination + "\\" + dbName + ".bak", DeviceType.File); bkpDatabase.Devices.Add(bkpDevice); bkpDatabase.Incremental = false; bkpDatabase.Initialize = true; // Perform the backup bkpDatabase.SqlBackup(sqlServer); if (System.IO.File.Exists(destination + "\\" + dbName + ".bak")) { return true; } else { return false; } } else { return false; } } else { return false; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload