现在的位置: 首页 > 综合 > 正文

c#数据备份恢复

2013年06月04日 ⁄ 综合 ⁄ 共 829字 ⁄ 字号 评论关闭

var Row = this.UltraWebGrid1.DisplayLayout.ActiveRow;
            string brName = (string)Row.Cells.FromKey("Name").Value;
            string filename = Server.MapPath("../");
            string pathname = filename + @"backupAndRestore/" + brName;

            string restore = "restore database sun from disk='" + pathname + "';";
            SqlConnection con = new SqlConnection("Data Source=192.168.1.101;Initial Catalog=sun;Persist Security Info=True;User ID=sa;Password=123");
            SqlCommand cmd = new SqlCommand(restore, con);
            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
                Response.Write("<script>alert('恢复成功! ');</script>");

            }
            catch
            {
                Response.Write("<script>alert('恢复失败! ');</script>");

            }
            finally
            {
                con.Close();
            }

抱歉!评论已关闭.