Set database to read only mode do something and set read write mode. Alter database mode using simple T-SQL statements.
USE [master]
GO
ALTER DATABASE [] SET READ_ONLY WITH NO_WAIT
GO
-- do some magic here
GO
ALTER DATABASE [] SET READ_WRITE WITH NO_WAIT
GO