请问大虾如何用delphi7备份和恢复mssql2000数据库,谢谢!
解决方案 »
- SOS紧急赏分帖!谁能给我一个delphi+mySql实现的分页查询功能的工程!
- 小女子求大家了,写的程序为什么内存失放不掉,导至死机,请高手帮我看看
- 更改表结构
- 请问variant和OleVariant这个变量类型的区别是什么?
- 用ADO连接ACCESS数据库,如何避免冲突
- 北京地之声科技公司
- 200分,高手请进!
- 急救!!!!分数不够我可以加,上限500!
- 如何设定EDIT的输入方式
- delphi中开发分布web应用时,web server 选择isapi时生成DLL文件,在浏览时出现xmlrowset未定义,请问如何处理。(delphi5,win2000 server
- delphi有中文帮助吗
- 谁能告诉我 *.CRD Windows Cardfile文件 怎么打开啊
procedure TForm23.Button1Click(Sender: TObject);
begin
if savedialog1.Execute then
begin
adoquery1.SQL.Text:='backup database mydatabase to disk='''+savedialog1.FileName+''' with init';
adoquery1.ExecSQL;
application.MessageBox('数据库备份成功','警告',MB_OK);
end;
end;//恢复
在查询分析器中运行
use master
goif exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_killspid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_killspid]
GOcreate proc p_killspid
@dbname sysname--要关闭进程的数据库名
as
declare @s nvarchar(1000)
declare tb cursor local for
select s='kill '+cast(spid as varchar)
from master..sysprocesses
where dbid=db_id(@dbname)open tb
fetch next from tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch next from tb into @s
end
close tb
deallocate tb
goprocedure TForm23.Button2Click(Sender: TObject);
begin
if opendialog1.Execute then
begin
adoquery1.SQL.Text:='use master;exec p_killspid mydatabase;Restore database madatabase From disk='''+opendialog1.FileName+''';Use mydatabase';
adoquery1.ExecSQL;
application.MessageBox('数据库完成恢复','警告',MB_OK);
end;
end;
procedure TF_bak.GradBtn2Click(Sender: TObject);
var adobackup:TAdocommand;
begin
if Edit1.Text='' then
begin
Application.MessageBox('请选择备份文件的存放路径!','提示',64);
exit;
end;
adobackup:=TAdocommand.Create(application);
adobackup.ConnectionString:=' Provider=SQLOLEDB.1;'+'Persist Security Info=False;User ID='+GetRegInfo(3)+';Password='+GetRegInfo(4)+';'+
'Initial Catalog='+GetRegInfo(2)+';Data Source='+GetRegInfo(1); adobackup.CommandText:='backup database RenSalMan to disk='''+Edit1.text+'''';
try
adobackup.Execute;
Application.MessageBox('备份成功!','提示',64);
adobackup.Free;
close;
except
Application.MessageBox('备份失败!','提示',64);
adobackup.Free;
exit;
end;
end;
procedure TF_restore.GradBtn1Click(Sender: TObject);
var adorestore:TAdocommand;
begin
if Edit1.Text='' then
begin
Application.MessageBox('请选择恢复文件!','提示',64);
exit;
end;
if application.MessageBox('此操作将使上次备份以来的所有数据丢失,是否继续?','恢复数据',33)=IDCANCEL then exit;
DM.Free;
adorestore:=TAdocommand.Create(application);
adorestore.ConnectionString:=' Provider=SQLOLEDB.1;'+'Persist Security Info=False;User ID='+GetRegInfo(3)+';Password='+GetRegInfo(4)+';'+
'Data Source='+GetRegInfo(1);
adorestore.CommandText:='restore database RenSalMan from disk='''+Edit1.Text+''' with replace';
try
adorestore.Execute;
adorestore.Free;
if Application.MessageBox( '恢复成功! 现在需要重新登陆软件,请按“确定” ','提示',64)=IDOK then application.Terminate;
except
Application.MessageBox('恢复失败!请确认恢复文件的路径和名称是否正确,或是否已关闭其它正在使用此数据库的程序!','提示',64);
adorestore.Free;
exit;
end;//end try
end;