restore failed for server

  • m restoring the database using the following code. but it is giving exception is Restoring failed for server 'administrator\sqlexpress'

    dim path as string=textbox2.text

    Dim SqlConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection("data source=administrator\sqlexpress; initial catalog=balaji; integrated security=SSPI;")

    SqlConnection.Open()

    Dim ServerConnection As ServerConnection = New Microsoft.SqlServer.Management.Common.ServerConnection(SqlConnection)

    Dim srv As Server = New Server(ServerConnection)

    'Declare a BackupDeviceItem by supplying the backup device file name in the constructor, and the type of device is a file.

    Dim bdi As BackupDeviceItem

    'bdi = New BackupDeviceItem(My.Settings.DefaultBackUpPath & "\NCS_Full_Backup1.bak", DeviceType.File)

    bdi = New BackupDeviceItem(path, DeviceType.File)

    ''Define a Restore object variable.

    Dim rs = New Restore

    'Set the NoRecovery property to true, so the transactions are not recovered.

    rs.NoRecovery = True

    rs.ReplaceDatabase = True

    'Add the device that contains the full database backup to the Restore object.

    rs.Devices.Add(bdi)

    rs.NoRecovery = False

    'Specify the database name.

    rs.Database = SqlConnection.Database.ToString()

    'Restore the full database backup with no recovery.

    Try

    'SqlConnection.ChangeDatabase("master")

    rs.SqlRestore(srv)

    Catch ex As Exception

    TextBox2.Text = ex.Message

    End Try

    what is wrong with this code?

  • Are there any other messages? Seems kind of vague.

    What is the full drive + path returned? Is it valid? Does the SQL Server service account have rights to read/write to it?



    Scott Duncan

    MARCUS. Why dost thou laugh? It fits not with this hour.
    TITUS. Why, I have not another tear to shed;
    --Titus Andronicus, William Shakespeare


Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply