none
sqlserver RRS feed

  • Question

  • m creating backup file using backup qyery

    then backup file is created. but when m restoring that file into new database it is giving exception as

    RESTORE FAILED FOR SERVER 'ADMINISTRATOR\SQLEXPRESS'

    M USING FOLLOWING CODE FOR RESTORING

    DIM PATH AS STRING=TEXTBOX1.TEXT

    Dim SqlConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection("data source=administrator\sqlexpress; initial catalog=rajitha; 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

     

     

    Saturday, May 10, 2008 6:51 AM