上次做了個項目
我把原作者的類擴充了一下
需要注意的時還原
create proc killspid (@dbname varchar(
as begin declare @sql nvarchar(
declare @spid int set @sql=
open getspid fetch next from getspid into @spid while @@fetch_status<>
fetch next from getspid into @spid end close getspid deallocate getspid end GO
在還原之前先執行這個存儲過程
using System
using System
using System
using System
namespace web
{
/// <summary>
/// DbOper類
/// </summary>
public class DbOper
{
private string server
private string uid
private string pwd
private string database
private string conn
/// <summary>
/// DbOper類的構造函數
/// </summary>
public DbOper()
{
conn=System
server=cut(conn
uid=cut(conn
pwd=cut(conn
database=cut(conn
}
public string cut(string str
{
string sub
sub=str
sub=sub
return sub
}
/// <summary>
/// 數據庫備份
/// </summary>
public bool DbBackup(string url)
{
SQLDMO
SQLDMO
try
{
oSQLServer
oSQLServer
oBackup
oBackup
oBackup
oBackup
oBackup
oBackup
oBackup
return true
}
catch
{
return false
throw
}
finally
{
oSQLServer
}
}
/// <summary>
/// 數據庫恢復
/// </summary>
public string DbRestore(string url)
{
if(exepro()!=true)//執行存儲過程
{
return
}
else
{
SQLDMO
SQLDMO
try
{
oSQLServer
oSQLServer
oRestore
oRestore
oRestore
oRestore
oRestore
oRestore
return
}
catch(Exception e)
{
return
throw
}
finally
{
oSQLServer
}
}
} /FooterTemplate> </asp
private bool exepro()
{
SqlConnection conn
SqlCommand cmd = new SqlCommand(
cmd
cmd
try
{
conn
cmd
return true
}
catch(Exception ex)
{
return false
}
finally
{
conn
}
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/11994.html