Automated Restore

  • I am trying to get an automated restore to run on a reporting instance of SQL Server.

    I tried setting the database to single user like this:

     Alter DATABASE CAT

     set SINGLE_USER

     WITH ROLLBACK After 60

     print 'Restoring Database'

     RESTORE DATABASE MyDB FROM DISK = @DBFileName

     

    It gives me an error message that the database is in use

    Any hints???

     

  • 1.Looks like some one is connected to your database. Could it be your process. When u restore your connection should point to Master DB not the DB that you are trying to restore?

    2.Will your restore be done in 60 seconds, if so and if you don't care about the connections to your destination database,you can programatically kill the process (spid) thats connected to the DB and run a restore.

    Thanks

    Sreejith

  • go to the query analyzer and type sp_who command to see who are the users that are using the database. If the running transactions are not critical (meaning that if you can afford to roll them back), change your SET SINGLE_USER AFTER 60 to SET SINGLE_USER WITH ROLLBACK IMMEDIATE. This option will immediately rollback any tranasaction that is active atthe time of start ofyour command.

     

    All the best

    Pankaj

    Pankaj Khanna
    Database Administrator - SQL Server 2000

    Keep hope to keep you intact...

  • I looks like the problem was with trying to run the restore procedure from the Database I was trying to restore.  One I moved it to the master database everything works.

    Thanks.

     

    Michael

Viewing 4 posts - 1 through 3 (of 3 total)

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