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);
}
}
}
}

相关文章:

  • 2021-10-02
  • 2022-02-19
  • 2021-06-20
  • 2021-06-06
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2022-03-04
猜你喜欢
  • 2021-08-31
  • 2022-02-19
  • 2022-12-23
  • 2022-02-14
  • 2021-08-23
  • 2021-12-05
相关资源
相似解决方案