Sample code for 30+ languages & platforms
SQL Server

bz2 Compress File

Compress a file to the bz2 file format.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    -- This example requires the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @bz2 int
    EXEC @hr = sp_OACreate 'Chilkat.Bz2', @bz2 OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    -- Compress the file qa_data/hamlet.xml to create qa_output/hamlet.bz2
    EXEC sp_OAMethod @bz2, 'CompressFile', @success OUT, 'qa_data/hamlet.xml', 'qa_output/hamlet.bz2'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @bz2, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @bz2
        RETURN
      END


    PRINT 'Success.'

    EXEC @hr = sp_OADestroy @bz2


END
GO