Code for compressing the database backup file of sqlserver2000 in a program

Source: Internet
Author: User
Code for compressing the database backup file of sqlserver2000 in a program

Code for compressing the database backup file of SQL Server in a program

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?
The 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.
The 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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.