• 在代码中恢复sql server 数据库


     1 SQLDMO.SQLServer svr = new SQLDMO.SQLServerClass();
     2            try
     3            {
     4                svr.Connect(Encrypt.UNDES("localhost","sa","password");
     5                SQLDMO.QueryResults qr = svr.EnumProcesses(-1);
     6                int iColPIDNum = -1;
     7                int iColDbName = -1;
     8                for (int i = 1; i <= qr.Columns; i++)
     9                {
    10                    string strName = qr.get_ColumnName(i);
    11                    if (strName.ToUpper().Trim() == "SPID")
    12                    {
    13                        iColPIDNum = i;
    14                    }

    15                    else if (strName.ToUpper().Trim() == "DBNAME")
    16                    {
    17                        iColDbName = i;
    18                    }

    19                    if (iColPIDNum != -1 && iColDbName != -1)
    20                        break;
    21                }

    22
    23                for (int i = 1; i <= qr.Rows; i++)
    24                {
    25                    int lPID = qr.GetColumnLong(i, iColPIDNum);
    26                    string strDBName = qr.GetColumnString(i, iColDbName);
    27                    if (strDBName.ToUpper() == DBName.ToUpper())
    28                        svr.KillProcess(lPID);
    29                }

    30
    31                SQLDMO.Restore res = new SQLDMO.RestoreClass();
    32                res.Action = 0;
    33                res.Files = ServiceFolder;
    34                res.Database = DBName;
    35                res.ReplaceDatabase = true;
    36                res.SQLRestore(svr);
    37            }

    38            catch
    39            {
    40                throw;
    41            }

    42            finally
    43            {
    44                svr.DisConnect();
    45            }
     
    46
  • 相关阅读:
    Eclipse安装python注意事项
    C# 计算文件MD5
    C# 为私有方法添加单元测试(反射)
    .net 操作sftp服务器
    在ASP.NET MVC中使用Unity进行依赖注入的三种方式
    ASP.NET Web API 安全筛选器
    Token Based Authentication in Web API 2
    IIS中查看W3P.exe进程对应的应用程序池的方法
    WCF自定义Header
    sqlserver 用 RowNumber 分组
  • 原文地址:https://www.cnblogs.com/elzero/p/869325.html
Copyright © 2020-2023  润新知