• 在ASP.NET中备份数据库以及还原(不成熟)


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Data.SqlClient;
    using System.Data;

    namespace Glonee.DAL
    {
    /// <summary>
    /// 数据库操作类
    /// </summary>
    public class BackupService
    {
    /// <summary>
    /// 备份数据库
    /// </summary>
    public static int BackUpToGo(string txtPath, string txtName)
    {
    string sql = "backup database Glonee to disk='" + txtPath.Trim() + "\" + txtName.Trim() + ".bak'";
    return SQLHelper.ExcuteNonQuery(sql);
    }
    /// <summary>
    /// 还原数据库
    /// </summary>
    /// <param name="txtPath"></param>
    /// <returns></returns>
    public static int restore(string txtPath)
    {
    string sql = "use master;restore database @name from disk=@path With Replace;";
    SqlParameter[] param =
    {
    new SqlParameter("@name","Glonee"),
    new SqlParameter("@path",txtPath)
    };
    try
    {
    return SQLHelper.ExcuteNonQuery(sql, param);
    }
    catch
    {
    throw;
    }
    }
    public static void KillThread(string MyId)
    {
    string strSQL = "select spid from master..sysprocesses where dbid=db_id('Glonee') ";
    DataTable table = SQLHelper.ExcuteTable(strSQL).Tables[0];
    for (int row = 0; row<=table.Rows.Count-1;row++)
    {
    string id = table.Rows[row][0].ToString();
    if (id== MyId)
    {
    return;
    }
    string sql = "kill "+id;
    SQLHelper.ExcuteNonQuery(sql);
    }
    }
    }
    }

  • 相关阅读:
    前端React 条件渲染
    hbuilder小白干货之快捷键大全
    前端React 元素渲染
    mybatis学习笔记五(映射)
    mybatis学习笔记四(配置文件)
    mybatis学习笔记二(sqlsession与开发dao)
    mybatis学习笔记三(动态sql)
    mybatis学习笔记一(mybatis概述)
    必备idea 插件plugins 提高编码效率
    shell提升篇
  • 原文地址:https://www.cnblogs.com/ZaraNet/p/9433448.html
Copyright © 2020-2023  润新知