SQL 2000 備份資料庫,排它訪問權。解決方法

2021-08-29 15:37:00 字數 1675 閱讀 3228

--還原資料庫時資料庫正在使用導致資料庫無會還原,此儲存過存在msater資料庫下建立。exec killspid cztdba 結束此資料庫的程序,這樣才能還原資料庫

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('''+@dbname+''')'

exec (@sql)

open getspid

fetch next from getspid into @spid

while @@fetch_status <> -1

begin

exec('kill '+@spid)

fetch next from getspid into @spid

end

close getspid

deallocate getspid

end

/**

* 還原資料庫備份檔案

* @return

*/public string restoredatabase() catch (filenotfoundexception e)

//資料夾不存在建立

uploadedfilehandler.settargetpath(path);

//得到上傳後檔案物件

file file = uploadedfilehandler.doupload(data, datafilename);

if (file.exists()) catch(exception e)

/*** 不新增這句會找不到資料庫裡的表,新增上這句會出現異常但是對系統無影響,所以把此異常遮蔽

*/try catch(exception e)

}return input;

} /**

* 備份資料庫檔案

* @return

*/public string backdatabase() catch (filenotfoundexception e)

//資料夾不存在建立

uploadedfilehandler.settargetpath(path.tostring());

downfilename = dateutil.getdatetime("yyyymmddhhmmss", new date()) + ".back";

//得到檔案在系統中實際位址

//開始備份檔案

stringbuffer sbf = new stringbuffer("backup database cztdba to disk='")

jdbctemplate.execute(sbf.tostring());

try catch (filenotfoundexception e)

return success;

}

Sql 2000 資料庫備份例項

資料庫備份例項 資料庫備份例項 朱二 2004年5月 備份策略 資料庫名 test 備份檔案的路徑e backup 每個星期天凌晨1點做一次完全備份,為保險起見,備份到兩個同樣的完全備份檔案test full a.bak和test full b.bak 每天1點 除了星期天 做一次差異備份,分別備份...

SQL2000自動備份壓縮刪除資料庫

create proc sp backup asdeclare dbname varchar 20 cmd1 nvarchar 120 cmd2 varchar 120 cmd3 varchar 120 i int,filename varchar 80 path varchar 80 set db...

SQL2000資料庫定期自動備份與修改

2009 11 19 烈火網 投遞稿件 我有話說 在sql server企業管理器中,可以設定資料庫的定期自動備份計畫,並通過啟動sql server agent 來自動執行備份計畫,具體步驟如下 1 開啟企業管理器,在控制台根目錄裡中依次點開 microsoft sql servers sql s...