日期:2014-05-18  浏览次数:20781 次

各位大仙看看我这出什么错了....
 
  各位大仙看看我这程序出什么错了,恢复数据库这块好像有问题。。执行到红色的函数那里运行出问题,还原不成功。。。


 
C# code
else//恢复数据库
        {
            try
            {
                if (fulFile.HasFile)
                {
                    SqlCommand command = new SqlCommand("use master;restore database @name from disk=@path;", connection);
                    connection.Open();
                    string path = fulFile.PostedFile.FileName;  //获取备份文件
                    command.Parameters.AddWithValue("@name", dbName);
                    command.Parameters.AddWithValue("@path", path);
                   [color=#FF0000] command.ExecuteNonQuery();[/color]
                    ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>alert('还原成功!');</script>");
                    connection.Close();
                }
                else
                {
                    ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>alert('请先选择备份的文件位置!');</script>");
                }
            }
            catch (Exception ex)
            {
                 ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>alert('还原数据库失败!原因是:"+ex.Message+"');</script>");        
            }
        }


------解决方案--------------------
是master这个数据库吗
------解决方案--------------------
SqlCommand command = new SqlCommand("use master restore database @name from disk='@path' ", connection);