当前位置:编程学习 > C#/ASP.NET >>

急求:大家帮忙给我注释一段代码,有关数据库恢复的

string sql="Persist Security Info=False;Data Source=Localhost;Integrated security=SSPI;Initial catalog=paike; ";
sql+="server=(local);Database=paike;Uid=sa;Pwd='123456'"; 
SqlConnection con=new SqlConnection(sql);
con.open();
SqlCommand cmd = new SqlCommand("SELECT spid FROM sysprocesses ,sysdatabases WHERE sysprocesses.dbid=sysdatabases.dbid AND sysdatabases.Name='paike'", con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
ArrayList list = new ArrayList();
while(dr.Read())
{
list.Add(dr.GetInt16(0));
}
dr.Close();
for(int i = 0; i < list.Count; i++)
{
cmd = new SqlCommand(string.Format("KILL {0}", list[i]), con);
cmd.ExecuteNonQuery();


SqlCommand cmdRT = new SqlCommand();
cmdRT.CommandType = CommandType.Text;
cmdRT.Connection = con;
cmdRT.CommandText = @"restore database paike from disk='d:\paike'"; 

try
{
cmdRT.ExecuteNonQuery();
MessageBox.Show("恢复成功.");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
在执行过程中提示"系统错误"那里有错啊
请大家也帮忙改一下
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,