怎樣壓縮sql server2000的數(shù)據(jù)庫備份文件,像rar一樣?小弟有一7m的sql server2000
數(shù)據(jù)庫備份文件,在程序中怎樣壓縮啊?
復制代碼 代碼如下:
procedure TForm1.Button2Click(Sender: TObject);
var
SHExecInfo: SHELLEXECUTEINFO;
begin
SHExecInfo.cbSize := sizeof(SHELLEXECUTEINFO);
SHExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
SHExecInfo.Wnd := Handle;
SHExecInfo.lpVerb := nil;
SHExecInfo.lpFile := 'WinRAR.exe';
SHExecInfo.lpParameters := 'a e:\qwqw.rar e:\qwqw';
SHExecInfo.lpDirectory := nil;
SHExecInfo.nShow := SW_SHOW;
SHExecInfo.hInstApp := Handle;
ShellExecuteEx(@SHExecInfo);
WaitForSingleObject(SHExecInfo.hProcess, INFINITE);
CloseHandle(SHExecInfo.hProcess);
ShellExecute(application.MainForm.Handle,'open','winrar.exe',PChar('a e:\zqzq.rar e:\zqzq'),'',SW_show);
ShowMessage('壓縮完畢!'); }
這是一段壓縮圖片的代碼,壓縮文件原理相同,只需稍做改動即可。
復制代碼 代碼如下:
var
mss: TMemoryStream;
zip: TDeCompressionStream;
zip1: TCompressionStream;
fs : TFileStream;
fBuf: Array[0..16383] of Byte;
flen: Integer;
//從數(shù)據(jù)庫中取出圖片
//...寫出SQL語句以取得有圖片的記錄,此處從略
mss := TMemoryStream.Create;
fs := TFileStream.Create('filename.jpg',fmCreate or fmOpenWrite);
try
TBlobField(Que.FieldByName('pic')).SaveToStream(mss);
zip := TDeCompressionStream.Create(fs);
try
flen := zip.Read(fbuf, SizeOf(fBuf));
while flen > 0 do begin
fs.Write(fbuf, flen);
flen := zip.Read(fbuf, SizeOf(fBuf));
end;
finally
FreeAndNil(zip);
end;
finally
mss.Free;
fs.Free;
end;
//將文件filename.jpg中的圖片保存到數(shù)據(jù)庫
//...寫出SQL語句,打開Que,并定位到要保存圖片的記錄,此處從略
fs := TFileStream.Create('filename.jpg',fmOpenRead);
mss := TMemoryStream.Create;
try
zip1 := TCompressionStream.Create(clDefault,mss);
try
flen := fs.Read(fbuf, SizeOf(fBuf));
while flen > 0 do begin
zip1.Write(fbuf, flen);
flen := fs.Read(fbuf, SizeOf(fBuf));
end;
//保存到數(shù)據(jù)庫
TBlobField(Que.FieldByName('pic')).LoadFromStream(mss);
Que.UpdateBatch();
//...
finally
zip1.Free;
end;
finally
fs.Free;
mss.Free;
end;
您可能感興趣的文章:- sql server通過腳本進行數(shù)據(jù)庫壓縮全備份的方法【推薦】
- sql server 2008 壓縮備份數(shù)據(jù)庫(20g)
- mysql數(shù)據(jù)庫備份命令分享(mysql壓縮數(shù)據(jù)庫備份)
- sqlserver 數(shù)據(jù)庫壓縮與數(shù)據(jù)庫日志(ldf)壓縮方法分享
- 自動備份mssql server數(shù)據(jù)庫并壓縮的批處理腳本
- DBCC SHRINKDATABASEMS SQL數(shù)據(jù)庫日志壓縮方法
- ms SQL server數(shù)據(jù)庫備份、壓縮與SQL數(shù)據(jù)庫數(shù)據(jù)處理的方法
- MS SQL SERVER 數(shù)據(jù)庫日志壓縮方法與代碼
- SQL Server 2000/2005/2008刪除或壓縮數(shù)據(jù)庫日志的方法