I want to make sure my database (SQL Server 2008) remains immutable, but still accessible for reads during some maintenance operations (backups, transitions to other DB servers etc),
how can I programmatically lock it for changes in C#?
I want to make sure my database (SQL Server 2008) remains immutable, but still
Share
You can execute an
ALTER DATABASE <mydb> SET READ_ONLYto put a database in read-only mode.If you want the command to fail if it can’t be executed immediately you specify it like this:
If you want to make it rollback all open connections you specify the command like this:
These options are well documented in SQL Server Books online