服务器“\\.\pipe\81DAC374-2583-49\tsql\query”恢复失败

发布于 2024-12-27 13:33:44 字数 1228 浏览 5 评论 0原文

错误:*“服务器 '\.\pipe\81DAC374-2583-49\tsql\query' 恢复失败。”*

我在此处收到错误 resDB .SqlRestore(sv) 我的备份工作正常,但恢复失败。过去两天我试图让它工作,但还没有成功。

   Public Shared Sub RestoreBackup()
        Dim sConnect As String = My.Settings.LICConnectionString
        Dim dbName As String

        Using cnn As New SqlConnection(sConnect)
            cnn.Open()
            dbName = cnn.Database.ToString()
            cnn.ChangeDatabase("master")

            Dim sc As New ServerConnection(cnn)
            Dim sv As New Server(sc)

            ' Check that I'm connected to the user instance
            MsgBox(sv.InstanceName.ToString())

            ' Create backup device item for the backup
            Dim bdi As New BackupDeviceItem("C:\Backup\LIC.bak", DeviceType.File)

            ' Create the restore object
            Dim resDB As New Restore()
            resDB.Devices.Add(bdi)
            resDB.NoRecovery = False
            resDB.ReplaceDatabase = True
            resDB.Database = dbName

            ' Restore the database
            resDB.SqlRestore(sv)
            MsgBox("Your database has been restored.")
        End Using
    End Sub

为什么会失败?感谢任何帮助。

Error : *"Restore failed for Server '\.\pipe\81DAC374-2583-49\tsql\query'."*

i get the error here resDB.SqlRestore(sv)
My backup works fine but restore fails.i am trying to get it working from the past two days and no luck yet.

   Public Shared Sub RestoreBackup()
        Dim sConnect As String = My.Settings.LICConnectionString
        Dim dbName As String

        Using cnn As New SqlConnection(sConnect)
            cnn.Open()
            dbName = cnn.Database.ToString()
            cnn.ChangeDatabase("master")

            Dim sc As New ServerConnection(cnn)
            Dim sv As New Server(sc)

            ' Check that I'm connected to the user instance
            MsgBox(sv.InstanceName.ToString())

            ' Create backup device item for the backup
            Dim bdi As New BackupDeviceItem("C:\Backup\LIC.bak", DeviceType.File)

            ' Create the restore object
            Dim resDB As New Restore()
            resDB.Devices.Add(bdi)
            resDB.NoRecovery = False
            resDB.ReplaceDatabase = True
            resDB.Database = dbName

            ' Restore the database
            resDB.SqlRestore(sv)
            MsgBox("Your database has been restored.")
        End Using
    End Sub

Why does it fail??Any Help Appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哽咽笑 2025-01-03 13:33:45

您似乎正在尝试通过主数据库进行恢复。您需要将 cnn.ChangeDatabase("master") 更改为 cnn.ChangeDatabase("LIC")。

编辑:

或者,删除行 cnn.ChangeDatabase("master") 一起,并在实例化 Restore 类后添加以下行:

resDB.Action = RestoreActionType.Database

此外,如果备份来自另一台服务器,您可能需要使用 RelocateFile 查看代码> - 如何从 C# 恢复数据库

It looks like you're trying to restore over the master database. You will need to change cnn.ChangeDatabase("master") to cnn.ChangeDatabase("LIC").

EDIT:

Alternatively, remove the line cnn.ChangeDatabase("master") altogether and add the following line after instantiating the Restore class:

resDB.Action = RestoreActionType.Database

Also, if the backup is from another server you may want to look at using RelocateFile - How to restore a database from C#

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文