110,538
社区成员
发帖
与我相关
我的任务
分享
public void Kill_db()
{
DataBase db = new DataBase();
SqlConnection conn = db.Get_conn(); //连接数据库
string strSQL = "select spid from master..sysprocesses where dbid=db_id( 'people') ";
SqlDataAdapter Da = new SqlDataAdapter(strSQL, conn);
DataTable spidTable = new DataTable();
Da.Fill(spidTable);
SqlCommand Cmd = new SqlCommand();
Cmd.CommandType = CommandType.Text;
Cmd.Connection = conn;
for (int iRow = 0; iRow <= spidTable.Rows.Count - 1; iRow++)
{
Cmd.CommandText = "kill " + spidTable.Rows[iRow][0].ToString(); //强行关闭用户进程
Cmd.ExecuteNonQuery();
}
conn.Close();
conn.Dispose();
db = null;
}
create proc db_back
@path varchar(100)
as
backup log people to disk=@path restore database people from disk=@path
GO
我是用存储过程来还原的,应该也可以的