菜鸟问题:谨请大家给点建议,不胜感激:数据库如何进行手动或自动备份? Paradox类型数据库(如jekydb.db)如何在系统运行后,数据库未打开/打开情况下进行手动或自动备份??最好举例答疑,不胜感激!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 手动,copy到另外一个路径。自动,如果是运行于NT,2000和XP的话,有个自动备份任何文件的功能,如果是98或ME,可能通过写程序来实现自动备份 我只知道用windows文件系统的备份方法,但是我觉得就象数据的压缩一样,应该可以通过COM组件对象来备份的才对(猜测) 以下是我以前写的,请参考!function GetConnectStr(DbFile: string): string;begin Result := 'Provider=Microsoft.Jet.OLEDB.4.0;'+ 'Password="";'+ 'User ID=Admin;'+ Format('Data Source = %S;',[DbFile])+ 'Mode=Share Deny None;Extended Properties=""';end;procedure TFrmDataBak.DataBak(BakFile: string);var SourceFile: string; DestFile: string; BakADOC: TADOConnection; ConnectStr: string; E1: TADOCommand; _SQL: string; TblNames: TStringList; i,j: integer; Nd: string; isNd: Boolean; FieldNames: TStringList;begin Screen.Cursor := crHourGlass; BakADOC := TADOConnection.Create(Nil); E1 := TADOCommand.Create(Nil); TblNames := TStringList.Create; FieldNames := TStringList.Create; DbInfo.ADOC.Connected := False; Nd := Format('%4D',[SpinEdit1.Value]); SourceFile := AppPath+'Db\LandDB.mdb'; DestFile := BakFile; SingleFileCopy(SourceFile,DestFile); try ConnectStr := GetConnectStr(DestFile); BakADOC.ConnectionString := ConnectStr; BakADOC.LoginPrompt := False; BakADOC.Connected := True; E1.CommandType := cmdText; E1.Connection := BakADOC; BakADOC.GetTableNames(TblNames,False); ProgressBar1.Min := 0; ProgressBar1.Max := TblNames.Count; ProgressBar1.Step := 1; for i := 0 to TblNames.Count-1 do begin Label3.Caption := Format('正在处理%S...',[TblNames[i]]); Application.ProcessMessages; BakADOC.GetFieldNames(TblNames[i],FieldNameS); IsNd := False; for j := 0 to FieldNameS.Count-1 do begin if UpperCase(FieldNameS[j]) = UpperCase('Nd') then begin IsNd := True; Break; end; end; if IsNd then begin _SQL := Format('Delete From %S Where %S',[TblNames[i],Tj]); E1.CommandText := _SQL; E1.Execute; end; ProgressBar1.StepIt; end; TipInfo('数据备份完成!'); finally BakADOC.Connected := False; E1.Free; BakADOC.Free; TblNames.Free; FieldNames.Free; DbInfo.ADOC.Connected := True; Screen.Cursor := crDefault; end;end;procedure TFrmDataBak.FormCreate(Sender: TObject);begin SpinEdit1.Value := StrtoInt(Yyxq.Nd);end;procedure TFrmDataBak.BitBtn1Click(Sender: TObject);var Dir: string;begin if SelectDirectory('选择要备份数据目录', '', Dir) then begin if Copy(Dir,Length(Dir),1)<>'\' then begin Dir := Dir+'\'; end; if QueryInfo(Format('选择的目录%S是要备份的数据目录吗?',[Dir])) then begin if QueryInfo('确实要备份数据吗?') then begin DataBak(Dir+BackFile); end; end; end;end;procedure TFrmDataBak.SpinEdit1Change(Sender: TObject);var Nd: string;begin Nd := Format('%4D',[SpinEdit1.Value]); RadioGroup1.Items.Clear; RadioGroup1.Items.Append(Format('仅%S年数据',[Nd])); RadioGroup1.Items.Append(Format('%S年以前所有数据',[Nd])); RadioGroup1.Items.Append(Format('%S年以后所有数据',[Nd])); RadioGroup1.ItemIndex := 0; BackFile := Format('Bak%S.mdb',[Nd]);end;procedure TFrmDataBak.RadioGroup1Click(Sender: TObject);var Nd: string;begin Nd := Format('%4D',[SpinEdit1.Value]); case RadioGroup1.ItemIndex of 0: begin BackFile := Format('Bak%S.mdb',[Nd]); Tj := Format('Nd <> ''%S''',[Nd]); end; 1: begin BackFile := Format('Bak%SB.mdb',[Nd]); Tj := Format('Nd > ''%S''',[Nd]); end; 2: begin BackFile := Format('Bak%SA.mdb',[Nd]); Tj := Format('Nd < ''%S''',[Nd]); end; end;end;end. 感激frend大哥,但我在具体修改后编译时,好多通不过,能否赐教?出错如下: DbInfo.ADOC.Connected := False;//1Nd := Format('%4D',[SpinEdit1.Value]);//2SingleFileCopy(SourceFile,DestFile);//3if SelectDirectory('选择要备份数据目录', '', Dir) then//4if QueryInfo(Format('选择的目录%S是要备份的数据目录吗?',[Dir])) then//5_SQL := Format('Delete From %S Where %S',[TblNames[i],Tj]);//6Tj := Format('Nd <> ''%S''',[Nd]);//7BackFile := Format('Bak%S.mdb',[Nd]);//8SourceFile := AppPath+'Db\LandDB.mdb';//9TipInfo('数据备份完成!');///10SpinEdit1.Value := StrtoInt(Yyxq.Nd);//11提示未定义的标识符有:1中‘dbinfo',2-'spinedit1.value'请问spinedit1为啥组件?3-'singlefilecopy',4-selectdirectory,5-queryinfo,6-tj,7-tj,8-backfile,9-AppPath 其中'AppPath'是否为一常量?10-‘tipinfo',11-右边解释?是否USES 中添加...??另外,还需增加组件??望各位海涵!!! spinedit1是他的一个控件,估计是Edit控件DbInfo要自己定义的selectdirectory在FileCtrl单元queryinfo等是他自己定义的东东 有一点眉目,谢谢!spinedit好象不是EDIT控件,如果是,程序中应该是:spinedit1.text,而不是spinedit1.value 唉,重新包装Edit了嘛,加了个属性Value 问个外挂多线程的问题 500分求QQ客户端源码 query查询某时间段内的记录,可是运行时有误,请高手进来看看呀,(有源码) 帮小弟一把!!! 如何读取文本文档的内容。 将delphi转换成c 我用FastReport做报表时遇到的问题??请帮助!! 怎样晋升到高手行列,郁闷中.......... 如何让程序在OS启动时自动运行? 怎样使用ODBC连接数据库? 求合租! 喜欢陈佩斯小品的朋友请进来!
自动,如果是运行于NT,2000和XP的话,有个自动备份任何文件的功能,如果是98或ME,可能通过写程序来实现自动备份
function GetConnectStr(DbFile: string): string;
begin
Result :=
'Provider=Microsoft.Jet.OLEDB.4.0;'+
'Password="";'+
'User ID=Admin;'+
Format('Data Source = %S;',[DbFile])+
'Mode=Share Deny None;Extended Properties=""';
end;procedure TFrmDataBak.DataBak(BakFile: string);
var
SourceFile: string;
DestFile: string;
BakADOC: TADOConnection;
ConnectStr: string;
E1: TADOCommand;
_SQL: string;
TblNames: TStringList;
i,j: integer;
Nd: string;
isNd: Boolean;
FieldNames: TStringList;
begin
Screen.Cursor := crHourGlass;
BakADOC := TADOConnection.Create(Nil);
E1 := TADOCommand.Create(Nil);
TblNames := TStringList.Create;
FieldNames := TStringList.Create;
DbInfo.ADOC.Connected := False; Nd := Format('%4D',[SpinEdit1.Value]);
SourceFile := AppPath+'Db\LandDB.mdb';
DestFile := BakFile;
SingleFileCopy(SourceFile,DestFile); try
ConnectStr := GetConnectStr(DestFile);
BakADOC.ConnectionString := ConnectStr;
BakADOC.LoginPrompt := False;
BakADOC.Connected := True; E1.CommandType := cmdText;
E1.Connection := BakADOC; BakADOC.GetTableNames(TblNames,False);
ProgressBar1.Min := 0;
ProgressBar1.Max := TblNames.Count;
ProgressBar1.Step := 1;
for i := 0 to TblNames.Count-1 do
begin
Label3.Caption := Format('正在处理%S...',[TblNames[i]]);
Application.ProcessMessages;
BakADOC.GetFieldNames(TblNames[i],FieldNameS);
IsNd := False;
for j := 0 to FieldNameS.Count-1 do
begin
if UpperCase(FieldNameS[j]) = UpperCase('Nd') then
begin
IsNd := True;
Break;
end;
end;
if IsNd then
begin
_SQL := Format('Delete From %S Where %S',[TblNames[i],Tj]);
E1.CommandText := _SQL;
E1.Execute;
end;
ProgressBar1.StepIt;
end;
TipInfo('数据备份完成!');
finally
BakADOC.Connected := False;
E1.Free;
BakADOC.Free;
TblNames.Free;
FieldNames.Free;
DbInfo.ADOC.Connected := True;
Screen.Cursor := crDefault;
end;
end;procedure TFrmDataBak.FormCreate(Sender: TObject);
begin
SpinEdit1.Value := StrtoInt(Yyxq.Nd);
end;procedure TFrmDataBak.BitBtn1Click(Sender: TObject);
var
Dir: string;
begin
if SelectDirectory('选择要备份数据目录', '', Dir) then
begin
if Copy(Dir,Length(Dir),1)<>'\' then
begin
Dir := Dir+'\';
end;
if QueryInfo(Format('选择的目录%S是要备份的数据目录吗?',[Dir])) then
begin
if QueryInfo('确实要备份数据吗?') then
begin
DataBak(Dir+BackFile);
end;
end;
end;
end;procedure TFrmDataBak.SpinEdit1Change(Sender: TObject);
var
Nd: string;
begin
Nd := Format('%4D',[SpinEdit1.Value]);
RadioGroup1.Items.Clear;
RadioGroup1.Items.Append(Format('仅%S年数据',[Nd]));
RadioGroup1.Items.Append(Format('%S年以前所有数据',[Nd]));
RadioGroup1.Items.Append(Format('%S年以后所有数据',[Nd]));
RadioGroup1.ItemIndex := 0;
BackFile := Format('Bak%S.mdb',[Nd]);
end;procedure TFrmDataBak.RadioGroup1Click(Sender: TObject);
var
Nd: string;
begin
Nd := Format('%4D',[SpinEdit1.Value]);
case RadioGroup1.ItemIndex of
0:
begin
BackFile := Format('Bak%S.mdb',[Nd]);
Tj := Format('Nd <> ''%S''',[Nd]);
end;
1:
begin
BackFile := Format('Bak%SB.mdb',[Nd]);
Tj := Format('Nd > ''%S''',[Nd]);
end;
2:
begin
BackFile := Format('Bak%SA.mdb',[Nd]);
Tj := Format('Nd < ''%S''',[Nd]);
end;
end;
end;end.
DbInfo.ADOC.Connected := False;//1
Nd := Format('%4D',[SpinEdit1.Value]);//2
SingleFileCopy(SourceFile,DestFile);//3
if SelectDirectory('选择要备份数据目录', '', Dir) then//4
if QueryInfo(Format('选择的目录%S是要备份的数据目录吗?',[Dir])) then//5
_SQL := Format('Delete From %S Where %S',[TblNames[i],Tj]);//6Tj := Format('Nd <> ''%S''',[Nd]);//7
BackFile := Format('Bak%S.mdb',[Nd]);//8
SourceFile := AppPath+'Db\LandDB.mdb';//9
TipInfo('数据备份完成!');///10
SpinEdit1.Value := StrtoInt(Yyxq.Nd);//11
提示未定义的标识符有:1中‘dbinfo',2-'spinedit1.value'请问spinedit1为啥组件?3-'singlefilecopy',4-selectdirectory,5-queryinfo,6-tj,7-tj,8-backfile,9-AppPath 其中'AppPath'是否为一常量?10-‘tipinfo',11-右边解释?
是否USES 中添加...??另外,还需增加组件??望各位海涵!!!
DbInfo要自己定义的
selectdirectory在FileCtrl单元
queryinfo等是他自己定义的东东