我有一个应用程序执行SQL数据库的备份和恢复,这在本地计算机上工作正常,但是如果我对另一台机器上托管的SQL服务器运行此操作,我会收到以下错误
Microsoft.SqlServer.Management.Smo.FailedOperationException:服务器'25 .98.30.79'的备份失败.---> Microsoft.SqlServer.Management.Common.ExecutionFailureException:执行Transact-SQL语句或批处理时发生异常.---> System.Data.SqlClient.SqlException:无法打开备份设备'C:\ Program Files\State Manager\Archive\Capture\20100217152147*product*\databases*database**database*.bak'.操作系统错误3(系统找不到指定的路径.).
这似乎是由SQL服务器尝试将此文件写入其本地驱动器引起的.由于安全限制,我无法设置可以放置备份的共享区域.
有谁知道如何将这些数据移回到调用代码的机器上?
我的代码如下.
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;
}
}
Run Code Online (Sandbox Code Playgroud)
mar*_*c_s 17
不,这不会起作用 - SQL Server只能备份到物理连接到实际SQL Server计算机的驱动器.在任何情况下,您都无法将远程SQL Server备份到本地硬盘 - 这是不可能的(在SMO或SQL Server Management Studio中都不可能).