I have a stored procedure which migrate data from this database to another. To exclude any error, I want to make the database read only for every transaction except mine. I use SqlConnection and SqlCommand to run the script. Is there any way to do this?
Set the database to Single-user Mode
. When you put it in Single-user mode, then you have the only connection available. As long as you don't relinquish your connection, no one else can connect.
Be warned, this will close all existing connections by other users. But it will prevent other connections from being made.
More information: https://msdn.microsoft.com/en-us/library/ms345598.aspx