How programmatically enable READ COMMITTED SNAPSHOT in SQL Server?

∥☆過路亽.° 提交于 2019-12-04 10:13:11

问题


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


回答1:


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;



回答2:


ALTER DATABASE [dbname] SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK AFTER 20 SECONDS 


来源:https://stackoverflow.com/questions/262527/how-programmatically-enable-read-committed-snapshot-in-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!