当前位置: 首页 > 图文教程 > 数据库 > MSSQL > 怎样做sql server数据库的还原

MSSQL
Microsoft SQLServer的版本区别及选择
在SQL Server数据库中为标识(IDENTITY)列插入显式值
访问和更改关系数据,使用MSSQL外联接
一个查看MSSQLServer数据库空间使用情况的存储过程 SpaceUsed
SQL语句去掉重复记录,获取重复记录
复习一下sql server的差异备份
SQL中object_id函数的用法
SQL Server日期计算
找回SQL企业管理器里的SQL连接的密码的方法
mssql数据库系统崩溃后的一般处理步骤与方法
海量数据库的查询优化及分页算法方案
SQL Server连接中三个常见的错误分析
在程序中压缩sql server2000的数据库备份文件的代码
MS SQL SERVER 数据库日志压缩方法与代码
如何远程连接SQL Server数据库的图文教程
复制SqlServer数据库的方法
搜索sql语句
sql中返回参数的值
sql中生成查询的模糊匹配字符串
将Session值储存于SQL Server中

MSSQL 中的 怎样做sql server数据库的还原


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-17   浏览: 41 ::
收藏到网摘: n/a

 

以下为引用的内容:
  void restoreButton_Click(object sender, System.EventArgs e)
   {
    string path = pathTextBox.Text;
    string dbname = dbDropDownList.SelectedValue;

    string restoreSql = "use master;";
    restoreSql += "restore database @dbname from disk = @path;";
                string pai = "use master;ALTER DATABASE Wy SET OFFLINE WITH ROLLBACK IMMEDIATE;ALTER DATABASE Wy SET ONLINE WITH ROLLBACK IMMEDIATE";
                SqlConnection conn = new SqlConnection(ConnStr);
                SqlCommand com1 = new SqlCommand(pai, conn);

    SqlCommand myCommand = new SqlCommand(restoreSql, new SqlConnection(ConnStr));

    myCommand.Parameters.Add("@dbname", SqlDbType.Char);
    myCommand.Parameters["@dbname"].Value = dbname;
    myCommand.Parameters.Add("@path", SqlDbType.Char);
    myCommand.Parameters["@path"].Value = path;


    try
    {
                    conn.Open();
                    com1.ExecuteNonQuery();
                    conn.Close();
                    myCommand.Connection.Open();
     myCommand.ExecuteNonQuery();
                    infoLabel.Text = "恢复成功!<br>已经把备份"+path+"恢复到数据库";

    }
    catch(Exception ex)
    {
                    infoLabel.Text = "恢复失败!<br>出错信息如下:<br>" + ex.ToString();
    }
    finally
    {
     myCommand.Connection.Close();

    }
   }