3
我正在使用以下代碼使用C#和SMO恢復備份SQL數據庫。SMO「恢復服務器失敗」從文件恢復備份
void RestoreDatabaseWithSMO(string sConnect, string dbName, string backUpPath)
{
using (SqlConnection cnn = new SqlConnection(sConnect))
{
cnn.Open();
cnn.ChangeDatabase("master");
ServerConnection sc = new ServerConnection(cnn);
Server sv = new Server(sc);
if (!sv.Databases.Contains(dbName))
throw new Exception("this DataBase does not exist");
// Create backup device item for the backup
BackupDeviceItem bdi = new BackupDeviceItem(backUpPath, DeviceType.File);
// Create the restore object
Restore resDB = new Restore();
resDB.PercentComplete += new PercentCompleteEventHandler(percentComplete);
resDB.PercentCompleteNotification = 10;
resDB.Devices.Add(bdi);
resDB.NoRecovery = false;
resDB.ReplaceDatabase = true;
resDB.Database = dbName;
resDB.Action = RestoreActionType.Database;
// Restore the database
resDB.SqlRestore(sv);//Exception
}
}
但在最後一行我得到了異常下面!
{"Restore failed for Server '\\\\.\\pipe\\3F103E6E-3FD4-47\\tsql\\query'. "}
它有什麼問題?
你能指導我嗎?感謝
做到了爲什麼downvote? – 2011-12-30 04:44:04
我的猜測是因爲它是一個SMO問題的T-SQL答案。 – LJNielsenDk 2015-10-19 08:48:06