简体   繁体   English

服务器的还原数据库失败

[英]Restore Database failed for Server

Using this I successfully back up my database: 使用这个我成功备份了我的数据库:

Server myServer = new Server(@"PC-1\INSTANCE1");   
private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {

                Backup bkpDBFull = new Backup();
                bkpDBFull.Action = BackupActionType.Database;
                bkpDBFull.Database = "MyDatabase";
                BackupDeviceItem bkpDevice = new BackupDeviceItem(saveFileDialog1.FileName, DeviceType.File);
                bkpDBFull.Devices.Add(bkpDevice);
                bkpDBFull.BackupSetName = "Sample";
                bkpDBFull.BackupSetDescription = "Sample";
                bkpDBFull.SqlBackup(myServer);
            }
        }
        catch (SmoException ex)
        {
            throw new SmoException(ex.Message, ex.InnerException);
        }
    }

But I got an error in my restore Restore failed for Server 'PC-1\\INSTANCE1'. 但是我的恢复出错Restore failed for Server 'PC-1\\INSTANCE1'.

    private void button2_Click(object sender, EventArgs e)
    {
        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {
            Restore restoreDB = new Restore();
            restoreDB.Database = "MyDatabase";
            restoreDB.Action = RestoreActionType.Database;
            BackupDeviceItem bkpDevice = new BackupDeviceItem(openFileDialog1.FileName, DeviceType.File);
            restoreDB.Devices.Add(bkpDevice);
            restoreDB.ReplaceDatabase = true;
            restoreDB.SqlRestore(myServer);
        }
    }

I use the same server in both backup and restore. 我在备份和还原中使用相同的服务器。 Why it failed in restore although the backup is successful using the same server and database? 虽然备份使用相同的服务器和数据库成功,但为什么恢复失败?

One thing to rule out is it not liking the hyphen in the machine name, which you're not supposed to do really. 要排除的一件事是它不喜欢机器名称中的连字符,你不应该这样做。 If you try using the IP address as the server name this should rule this out. 如果您尝试使用IP地址作为服务器名称,则应该对此进行排除。

More likely to be a database in use thing as others have said. 正如其他人所说,更有可能成为一个正在使用的数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM