1.備份 if (DirectoryExists(EdtLJ.Text))=false then // EdtLJ.Text備份絕對(duì)路徑 begin ForceDirectories(EdtLJ.Text); end; strsql:=' backup database Demo to disk=' ; strsql:=strsql+#39+EdtLJ.Text+'/'+EdtMC.text+#39; //EdtMC.text備份文件名稱 Dia
1.備份
if (DirectoryExists(EdtLJ.Text))=false then // EdtLJ.Text備份絕對(duì)路徑
begin
ForceDirectories(EdtLJ.Text);
end;
strsql:=' backup database Demo to disk=' ;
strsql:=strsql+#39+EdtLJ.Text+'/'+EdtMC.text+#39; //EdtMC.text備份文件名稱
Dialogs.ShowMessage(strsql);
with adoquery2 do
begin
close;
sql.Text:=strsql;
execSql;
showmessage('備份成功!');
end;
或者
//開始備份
with adoquery1 do
begin
close;
sql.Clear;
sql.Add('Backup database library to disk=:p1 with init');
parameters.ParamByName('p1').Value:=self.SaveDialog1.FileName;
try
Execsql;
ShowMessage('備份成功!!');
except
ShowMessage('備份失敗!!');
exit;
end;
end; //End of 備份
2.還原
方法1
use master --這樣避免正在使用要還原的庫
go
declare cur cursor for
select spid from sysprocesses where dbid=db_id('Demo')
open cur
declare @spid int
declare @str varchar(100)
fetch next from cur into @spid
while @@fetch_status=0
begin
set @str=ltrim(@spid)
exec ('kill '+@str)
fetch next from cur into @spid
end
close cur
deallocate cur
go
restore database Demo from disk='d:/111.bak' with replace
方法2
alter database Demo set offline with rollback immediate
restore database Demo from disk='E:/1.bak' //還原語句
alter database Demo set online with rollback immediate
以上程序僅供參考,有什么不對(duì)的地方還請(qǐng)多多指教!
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com