none
Restoring a db returns ok, but Sql Server Management Studio shows status as (Restoring...)

    Question

  • I am trying to use SMO to backup/restore specific databases controlled by testers. The backup works, but when I return from the restore and check the database using Sql Server 2008 Management Studio, it shows the status of the restored database as still "(Restoring...)". It does not finish and remains in this state, so I am not sure what is going on.

    My test code for the restore is:

           static void Main(string[] args)
            {
                BackupDeviceItem bdi = default(BackupDeviceItem);
                bdi = new BackupDeviceItem(@"\CARDbackup\CARD_TEST01.bak", DeviceType.File);

                Server srv = default(Server);

                srv = new Server();
                srv.ConnectionContext.ServerInstance = "TestSVR";
                srv.ConnectionContext.LoginSecure = false;
                srv.ConnectionContext.Login = "sa";
                srv.ConnectionContext.Password = "password";
                srv.ConnectionContext.Connect();

                Backup(srv, bdi);
                Restore(srv, bdi);
            }

            static void Restore(Server srv, BackupDeviceItem bdi)
            {
                srv.Databases["TEST01"].Drop();
                Restore rs = default(Restore);
                rs = new Restore();
                rs.NoRecovery = true;
                rs.Devices.Add(bdi);
                rs.Database = "TEST01";

                try
                {
                    Console.WriteLine("Restoring TEST01");
                    rs.SqlRestore(srv);
                    Console.WriteLine("Full Database Restore complete");
                }

                catch (Exception ex)
                {
                    Console.WriteLine("Inner Exception Message: " + ex.InnerException.Message);
                }

                finally
                {
                    rs.Devices.Remove(bdi);
                }
            }

    • Edited by Bill2010 Wednesday, August 12, 2009 9:23 PM
    Wednesday, August 12, 2009 9:22 PM

Answers

  •             rs.NoRecovery = true;

    NO RECOVERY means the database wont come online! i.e. you still wish to apply a differential / log backup.

    changing it to false will bring the db online
    • Marked as answer by Bill2010 Thursday, August 13, 2009 4:24 PM
    Thursday, August 13, 2009 4:21 PM

All replies

  •             rs.NoRecovery = true;

    NO RECOVERY means the database wont come online! i.e. you still wish to apply a differential / log backup.

    changing it to false will bring the db online
    • Marked as answer by Bill2010 Thursday, August 13, 2009 4:24 PM
    Thursday, August 13, 2009 4:21 PM
  • thank you Nick
    but
    i has same problem ,and i tried to use this solution but it did'nt.
    please if there are any other solution,we wait
    Saturday, August 22, 2009 8:31 AM
  • your having the same issue restoring a db with SMO?
    Saturday, August 22, 2009 2:20 PM