How to restore backup done with SMO?

Asked

Viewed 76 times

0

I need to back up and restore using SMO. The backup I can do, now when I select it in the combobox by typing the server and database name of the error. Follow the code of the Restore button:

   private void restauracaoButton_Click(object sender, EventArgs e)
        {
            var server = new Microsoft.SqlServer.Management.Smo.Server(servidorTextBox.Text);
            var restore = new Microsoft.SqlServer.Management.Smo.Restore();
            restore.Database = databaseTextBox.Text;
            restore.Devices.AddDevice(backupsComboBox.SelectedValue.ToString(), Microsoft.SqlServer.Management.Smo.DeviceType.File);
            server.KillAllProcesses(databaseTextBox.Text);
            restore.SqlRestore(server);
            MessageBox.Show(string.Format("Backup '{0}' restaurado com sucesso.", backupsComboBox.Text), "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

inserir a descrição da imagem aqui

I will post the error print

inserir a descrição da imagem aqui

  • What mistake does the?

  • I posted just above Dener. Can you help me ?

  • Vc posted the routine to restore the bank.

  • In which line do you receive the error?

  • following error is posted when I click the restore backup button : An unhandled Exception of type 'Microsoft.SqlServer.Management.Smo.Failedoperationexception occurred' in Microsoft.SqlServer.Smoextended.dll

  • posted Dener error print

  • Capture this exception in Try catch, and post the error message.

  • I’ll take a moment

  • shows the same error

  • edited the question with the Dener error print

  • @user37846 edit the question with the exception Stacktrace and also put the Innerexception (message and Stacktrace).

  • I don’t know how to do this

  • In the window that appears with the exception (as shown in your image), click on "View Detail...", in the window that appears there is the message, stack trace and Inner Exception.

  • I don’t know how to do this

  • Instead of continuing to say you don’t know, I would advise you to take a look in this tutorial that teaches how to deal with exceptions in Visual Studio.

  • instead of pointing me to reorganize my question and my images , could help me at once!

  • 1

    @user37846 understand that in order to help you we need to understand what the problem is. There are several reasons why the backup might be failing the line that is failing, so without more debugging information, it will get complicated help you.

  • @user37846 it is important to organize your question, try to put yourself in the place of those who will answer, it is necessary for the community to be able to help you.

Show 13 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.