需要注意的是還原,還原的時(shí)候問(wèn)題最大了,有別的用戶(hù)使用數(shù)據(jù)庫(kù)的時(shí)候無(wú)法還原,解決辦法就是在master數(shù)據(jù)庫(kù)中添加一個(gè)存儲(chǔ)過(guò)程:
create proc killspid (@dbname varchar(20))
as
begin
declare @sql nvarchar(500)
declare @spid int
set @sql='declare getspid cursor for
select spid from sysprocesses where dbid=db_id('''[email protected]+''')'
exec (@sql)
open getspid
fetch next from getspid into @spid
while @@fetch_status<>-1
begin
exec('kill '[email protected])
fetch next from getspid into @spid
end
close getspid
deallocate getspid
end
go
在還原之前先執(zhí)行這個(gè)存儲(chǔ)過(guò)程,需要傳遞dbname,就是你的數(shù)據(jù)庫(kù)的名字。下邊是類(lèi)的原代碼:(web.config里的數(shù)據(jù)庫(kù)連接字符串是constr)
using system;
using system.configuration;
using system.data.sqlclient;
using system.data;
namespace web.base_class
{
/// <summary>
/// dboper類(lèi),主要應(yīng)用sqldmo實(shí)現(xiàn)對(duì)microsoft sql server數(shù)據(jù)庫(kù)的備份和恢復(fù)
/// <summary>
public class dboper
{
private string server;
private string uid;
private string pwd;
private string database;
private string conn;
/// <summary>
/// dboper類(lèi)的構(gòu)造函數(shù)
/// <summary>
public dboper()
{
conn=system.configuration.configurationsettings.appsettings["constr"].tostring();
server=cut(conn,"server=",";");
uid=cut(conn,"uid=",";");
pwd=cut(conn,"pwd=",";");
database=cut(conn,"database=",";");
}
public string cut(string str,string bg,string ed)
{
string sub;
sub=str.substring(str.indexof(bg)+bg.length);
sub=sub.substring(0,sub.indexof(";"));
return sub;
}
新聞熱點(diǎn)
疑難解答
圖片精選