Bringind a database offline or single user mode runs for ever?

  • Hi,

    Iam trying to move log files to different drive. In this process Iam trying bring the database offline by executing

    ALTER DATABASE database_name SET OFFLINE but keeps on running ,and giving no error message. So should I can do to bring database offline????? and aslo tried ALTER DATABASE database_name SET single_user it also running for ever???

    could you plz me in this?

  • Are there people connected to the database?

    If you want to move the files, detach the database, be sure you kill the users from it, and then attach it from the new location.

  • Hi Steve,

    there are no users connected to that database. When I ran sp_who2 it showing the logins are in sleeping mode. and when Iam trying to put the database in single_user mode I am getting the following error

    Msg 5061, Level 16, State 1, Line 1

    ALTER DATABASE failed because a lock could not be placed on database 'dbname'. Try again later.

    Msg 5069, Level 16, State 1, Line 1

    ALTER DATABASE statement failed.

    What this error mean?

  • Are all logins you see with sp_who2 your own? If not, other users are accessing the database. Kill those connections and try again.

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • To alter a database there must be no connections to the DB, sleeping or otherwise. You can either kill the connections or you can use the rollback immediate option on the alter database. Make sure that you are not connected to the database you're trying to alter.

    ALTER DATABASE database_name SET OFFLINE WITH ROLLBACK IMMEDIATE

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • sleeping connections are still connected.

    No one should show that db name in sp_who2. If they do, you need to remove them. That includes you connected with SSMS.

  • I did a sp_who2. Found the culprit. Asked them to get out. And then the database went offline.

  • I had this problem too when trying to take a database offline. See here for my full solution walkthrough...

    http://www.geakeit.co.uk/2010/12/11/sql-take-offline-fails-alter-database-failed-because-a-lock-could-not-error-5061/%5B/url%5D

Viewing 8 posts - 1 through 7 (of 7 total)

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