如何做备份Access库?//?
如何手动备份一个Access库,不是烤贝噢!!!!!!!!!!!
帮帮我高手们!!!!!!!!!
问题点数:0、回复次数:4Top
1 楼caoruomou(caoruomou)回复于 2003-12-02 19:05:41 得分 0
int iFileHandle;
iFileHandle = FileOpen("e:\\dndiy\\data\\dn.mdb", fmOpenWrite);
THandleStream *hStream = new THandleStream(iFileHandle);
TMemoryStream *mStream = new TMemoryStream();
mStream->CopyFrom(hStream,hStream->Size);
mStream->SaveToFile(DateToStr(Date())+".mdb");
delete mStream;
delete hStream;
FileClose(iFileHandle);
ShowMessage("备份成功!");
---------分数太少了Top
2 楼cuiyu616ok(大宇)回复于 2003-12-03 12:33:58 得分 0
DataModule2->ADOConnection1->Connected=false;
AnsiString asFileName=ExtractFileDir(Application->ExeName);
asFileName+="\\gdzcglxt.mdb";
//进度条
ProgressBar=new TProgressBar(this);
ProgressBar->Top=ProgressBarRect.Top;
ProgressBar->Left=ProgressBarRect.Left;
ProgressBar->Width=ProgressBarRect.Right-ProgressBarRect.Left;
ProgressBar->Height=ProgressBarRect.Bottom-ProgressBarRect.Top;
ProgressBar->Visible=True; //true
try
{
ProgressBar->Parent=StatusBar1;
ProgressBar->Min=-1;
//ProgressBar->Step=10000;
//ProgressBar->Max=10000;
ProgressBar->Step=2049;
//ProgressBar->Max=5000;
//
int iFromFileHandle,iToFileHandle;
int iFileLength;
int iBytesRead,iBytesWriten;
char *pszBuffer;
//
//iFileLength=0;
iFromFileHandle=FileOpen(asFileName,fmOpenRead);
iFileLength=FileSeek(iFromFileHandle,0,2);
//FromFileHandle=FileOpen(file,fmOpenRead);
//Lenght=FileSeek(FromFileHandle,0,2);
ProgressBar->Max=iFileLength; //
Label4->Caption="数据库大小:"+IntToStr(iFileLength)+"字节";
pszBuffer=new char[2049];
FileSeek(iFromFileHandle,0,0);
iToFileHandle=FileCreate(OpenDialog2->FileName);
do
{
iBytesRead=FileRead(iFromFileHandle,pszBuffer,2049);
if(iBytesRead<10)
{
Application->MessageBoxA("读取数据库文件出错,请从新备份!","提示",48);
BitBtn5->Enabled=true;
return;
}
iBytesWriten=FileWrite(iToFileHandle,pszBuffer,iBytesRead);
ProgressBar->StepIt();
}while(iBytesRead==2049);
//ProgressBar->Position=0; //
//delete ProgressBar; //
//ProgressBar->Max=0; //
Application->MessageBoxA("备份数据库成功!","提示",48);
delete[]pszBuffer;
FileClose(iFromFileHandle); //
FileClose(iToFileHandle);
OpenDialog2->FileName="";
OpenDialog1->FileName="";
//AnsiString asFileName=ExtractFileDir(Application->ExeName);
// asFileName+="\\people.mdb";
OpenDialog2->FileName=Memo2->Text;
OpenDialog1->FileName=Memo2->Text;
//DataModule2->ADOConnection1->ConnectionString=filename;
//SetCurrentDir(filename);
DataModule2->ADOConnection1->Connected=true;}
catch(...)
{
delete ProgressBar;
//AnsiString asFileName=ExtractFileDir(Application->ExeName);
// asFileName+="\\people.mdb";
OpenDialog2->FileName=Memo2->Text;
OpenDialog1->FileName=Memo2->Text;
DataModule2->ADOConnection1->Connected=true;Application->MessageBox("运行中出错!","错误!",48);
}
Top
3 楼lilachue(静水思雅)回复于 2003-12-03 13:34:48 得分 0
用FileCopy如何?
The CopyFile function copies an existing file to a new file.
BOOL CopyFile(
LPCTSTR lpExistingFileName, // pointer to name of an existing file
LPCTSTR lpNewFileName, // pointer to filename to copy to
BOOL bFailIfExists // flag for operation if file exists
);
Parameters
lpExistingFileName
Points to a null-terminated string that specifies the name of an existing file.
lpNewFileName
Points to a null-terminated string that specifies the name of the new file.
bFailIfExists
Specifies how this operation is to proceed if a file of the same name as that specified by lpNewFileName already exists. If this parameter is TRUE and the new file already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
Security attributes for the existing file are not copied to the new file.
File attributes (FILE_ATTRIBUTE_*) for the existing file are copied to the new file. For example, if an existing file has the FILE_ATTRIBUTE_READONLY file attribute, a copy created through a call to CopyFile will also have the FILE_ATTRIBUTE_READONLY file attribute. For further information on file attributes, see CreateFile.
Top
4 楼WYJBCB(阿菜)回复于 2004-01-30 22:30:15 得分 0
收藏Top




