我有一个执行SQL数据库备份和还原的应用程序,在本地计算机上运行良好,但是如果我针对另一台计算机上托管的SQL Server运行此应用程序,则会出现以下错误
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.).
这似乎是由SQL Server尝试将此文件写入其本地驱动器引起的。由于安全限制,我无法设置可以在其中放置备份的共享区域。
有谁知道我怎样才能将这些数据移回到调用代码的机器上?
我的代码如下。
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; } }
不,这将永远行不通-SQL Server只能备份到物理连接到实际SQL Server计算机的驱动器。在任何情况下,您 都无法 将远程SQL Server备份到本地硬盘上-几乎不可能(在SMO或SQL Server Management Studio中都不能)。