How to compress the database backup files of SQL Server, like rar? The younger brother has a 7 m SQL server2000
How do I compress database backup files in a program?
Copy codeThe Code is as follows:
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: \ qwq1_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 ('compressed! ');}
This is a piece of compressed image code. The compressed file works in the same principle. You only need to make some changes.
Copy codeThe Code is as follows:
Var
Mss: TMemoryStream;
Zip: TDeCompressionStream;
Zip1: TCompressionStream;
Fs: TFileStream;
FBuf: Array [0 .. 16383] of Byte;
Flen: Integer;
// Retrieve the image from the database
//... Write an SQL statement to obtain records with images.
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;
// Save the image in filename.jpg to the database
//... Write the SQL statement, open Que, and locate the record to save the image.
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;
// Save to database
TBlobField (Que. FieldByName ('pic '). LoadFromStream (mss );
Que. UpdateBatch ();
//...
Finally
Zip1.Free;
End;
Finally
Fs. Free;
Mss. Free;
End;