在SQL SERVER 中建了一个数据库 我希望通过程序而不是SQL SERVER的企业管理器工具来操作备份指定的数据库中的几个表几个视图的内容。用DELPHI 能否实现 SQL SERVER 备份事先指定好数据库中的几个表几个视图的内容?或者是完全备份SQL SERVER 的指定数据库?请知道的朋友给出解决问题的具体方法。 谢谢
解决方案 »
- ShellListView中如何删除选定的文件夹及它的子文件夹?
- MDI主窗体菜单按扭怎么能响应子窗体的事件!!
- 求助!!
- 找DELPHI群 本人是初级想同各高手学习交流 请加我,我的QQ:94170464
- 高手在上,小弟有事请教!!!急!!急!!急!!
- 誰有傳具軟件????哪里有此軟件下載!!!!!!!急救!!!!!!!!!!!!!!!!!!!!!!
- 录入的问题,如何将上一条记录的内容拷贝到新纪录中来待修改?
- 如何在执行一段代码时显示模态窗口?
- QRRichText 打印文本 ,怎样使右端对齐?多谢!
- 88分求教!有谁能把帮我把这个SQL语句优化一下呀?,表记录有40万条运行好慢呀。
- 谁能给我一个D7的DelphiMM.dll,我的Delphi没这个文件
- 棋牌游戏新开张,欢迎大家来测试!
procedure TBackupFrm.BitBtn2Click(Sender: TObject);
begin
if Edit1.Text= '' then
begin
Showmessage('无选择要保存的文件名');
exit;
end;
try
try
dmData.adoQryTmp.Active:= false;
dmData.adoQryTmp.SQL.Clear;
dmData.adoQryTmp.SQL.Add('BACKUP DATABASE [dzyl] TO DISK = '''+edit1.text+''' WITH INIT');
dmData.adoQryTmp.ExecSQL;
finally
begin
dmData.adoQryTmp.Active:= false;
Showmessage('数据库备份成功!');
end;
end;
except
on e:exception do
begin
ShowMessage('数据库备份失败!');
end;
end;
end;
---------------
恢复
procedure TBackupFrm.BitBtn4Click(Sender: TObject);
begin
if Edit2.Text = '' then
begin
showmessage('未选择要恢复的数据库文件!');
exit;
end;
with dmData do
begin
try
adocmmd.CommandText:='use master';
adocmmd.Execute;
adocmmd.CommandText:=' alter database dzyl set offline with rollback immediate';
adocmmd.Execute;
adocmmd.CommandText:='restore database dzyl from disk= '''+edit2.Text+''' with recovery ';
adocmmd.Execute;
adocmmd.CommandText:=' alter database dzyl set online with rollback immediate';
adocmmd.Execute;
showmessage('数据库恢复成功!');
application.Terminate;
except
on e:exception do
begin
showmessage('数据库恢复失败!'+e.Message);
end; end;
end;
end;
dmData.adoQryTmp连接的是系统MASTER数据库,备份还原之前应该关闭要备份还原的AdoConn数据库连接
AdoConn.Connected:=False;
http://www.delphibox.com/article.asp?articleid=2890
begin
StatusBar1.Panels[0].Text:=' 今天日期:'+FormatDateTime('yyyy"年"mm"月"dd"日"',now)+' 当前时间:'+FormatDateTime('hh"点"mm"分"ss"秒" ',now);
//截获当前日期、时间
end;再判断StatusBar1.Panels[0].Text里的值是不是与你指定的一致,如果是就执行备份程序!
如果不是就不管了!
if StatusBar1.Panels[0].Text="" then
begin
......
end
procedure TForm_Restore.BitBtnRestoreClick(Sender: TObject);
var
restorePath: string;
connStr,MySQL: string;
TReg: TRegistry;
begin
if EditRestore.Text = '' then
begin
Application.MessageBox('请选择数据路径','提示!',mb_ok+mb_iconinformation);
Exit;
end;
TReg := TRegistry.Create;
TReg.RootKey := HKEY_LOCAL_MACHINE;
try
if TReg.OpenKey('\SOFTWARE\Microsoft\MSSQLServer\Setup',False) then
begin
restorePath := TReg.ReadString('SQLPath');
end;
finally
TReg.CloseKey;
TReg.Free;
inherited;
end;
if restorePath = '' then
begin
Application.MessageBox('您为客户端,或者还没有安装SQL SERVER数据库,已经不能使用,请重新安装!','信息提示',mb_IconError+mb_ok);
Exit;
end;
if Application.MessageBox('注意!恢复数据库会使现在的数据丢失,建议您先备份','问题?',mb_yesno+mb_iconquestion) = idyes then
begin
Screen.Cursor := crhourglass;
Panel1.Visible := True;
connStr := 'Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password='+PassW+';Initial Catalog=master;Data Source='+OpIp+'';
ADOCrestor.Connected := False;
DM.ADOConn.Connected := False;
ADOCrestor.ConnectionString := connStr;
ADOCrestor.Connected := True;
MySQL := 'ALTER DATABASE HSGZGL SET OFFLINE WITH ROLLBACK IMMEDIATE';
with ADOQRestor do
begin
Close;
SQL.Clear;
SQL.Text := MySQL;
try
ExecSQL;
except
Application.MessageBox('数据库连接失败','错误!',mb_ok+mb_iconError);
Exit;
end;
end;
MySQL := 'Restore DataBase HSGZGL from disk=' + #39 + EditRestore.Text + #39 + ' with replace, ' +
' move ' + #39 + 'HSGZGL_data' + #39 + ' to ' + #39 + restorePath + '\Data\HSGZGL_data.MDF' + #39 +
', move ' + #39 + 'HSGZGL_log' + #39 + ' to ' + #39 + restorePath + '\Data\HSGZGL_data.LDF' + #39;
with ADOQRestor do
begin
Close;
SQL.Clear;
SQL.Text := MySQL;
try
ExecSQL;
except
Screen.Cursor := crarrow;
Panel1.Visible := False;
Application.MessageBox('数据库恢复失败,请确保不在被使用中','错误!',mb_ok+mb_iconError);
Exit;
end;
end;
MySQL := 'ALTER DATABASE HSGZGL SET ONLINE WITH ROLLBACK IMMEDIATE';
with ADOQRestor do
begin
Close;
SQL.Clear;
SQL.Text := MySQL;
try
ExecSQL;
except end;
end;
ADOCrestor.Connected := False;
connStr := 'Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password='+PassW+';Initial Catalog=HSGZGL;Data Source='+OpIp+'';
DM.ADOConn.ConnectionString := connStr;
DM.ADOConn.Connected := True;
Screen.Cursor := crarrow;
Panel1.Visible := False;
Application.MessageBox('数据库恢复成功','恭喜!',mb_ok+mb_iconinformation);