[英]Programmatically switching database to read-only and write on SQL Server
您能否以编程方式将数据库切换为写入访问权限并在C#中返回只读状态?
ALTER DATABASE database-name SET READ_ONLY
ALTER DATABASE database-name SET READ_WRITE
You can access the stored procedure in c# like below to execute the above lines. 您可以访问c#中的存储过程,如下所示执行上述行。
using (System.Data.SqlClient.SqlConnection con = new SqlConnection("YourConnection string")) {
con.Open();
SqlCommand cmd = new SqlCommand();
string expression = "Parameter value";
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Your Stored Procedure";
cmd.Parameters.Add("Your Parameter Name", SqlDbType.VarChar).Value = expression;
cmd.Connection = con;
using (IDataReader dr = cmd.ExecuteReader()) {
if (dr.Read()) {
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.