Bring mssql database online/offline

2 Feb

When trying to bring database offline, you may get this error:

ER DATABASE failed because a lock could not be placed on database ‘CJISData’. Try again later.
ALTER DATABASE statement failed. (Microsoft SQL Server, Error: 5061)

ALTER DATABASE %Database_Name% SET OFFLINE WITH ROLLBACK IMMEDIATE
To bring the database back online, just use:

ALTER DATABASE %Database_Name% SET ONLINE WITH ROLLBACK IMMEDIATE

http://social.msdn.microsoft.com/Forums/en/sqlsmoanddmo/thread/51d8872b-20cc-4311-9907-41ae44ca096a

If you get error because of user logged in:

select spid from master..sysprocesses where dbid=db_id(‘XXX’);
kill spid;

http://www.kodyaz.com/articles/kill-all-processes-of-a-database.aspx

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: