Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How programmatically enable READ COMMITTED SNAPSHOT in SQL Server?

I need to programmatically enable READ COMMITTED SNAPSHOT in SQL Server. How can I do that?

like image 569
João Vieira Avatar asked Nov 04 '08 17:11

João Vieira


2 Answers

I recommend switching to single-user mode first. That ensures you're the only connection. Otherwise, the query might be suspended.

From: http://msdn.microsoft.com/en-us/library/ms175095.aspx

When setting the READ_COMMITTED_SNAPSHOT option, only the connection executing the ALTER DATABASE command is allowed in the database. There must be no other open connection in the database until ALTER DATABASE is complete.

So, use this SQL:

ALTER DATABASE <dbname> SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
ALTER DATABASE <dbname> SET READ_COMMITTED_SNAPSHOT ON;
ALTER DATABASE <dbname> SET MULTI_USER;
like image 94
Bill Paetzke Avatar answered Sep 29 '22 08:09

Bill Paetzke


ALTER DATABASE [dbname] SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK AFTER 20 SECONDS 
like image 37
João Vieira Avatar answered Sep 29 '22 09:09

João Vieira