GZipStream compress problem in windows 2008 server R2

Posted on 2012-09-10
Medium Priority
Last Modified: 2013-05-15

I am using GZipStream to compress a database file that has been taken backup from Sql server 2008

Compression has been working fine other than windows server 2008 R2 environment.

I have attached the error message also.

Please help me solve this issue..

Thanks in advance..

The code am using to compress is,

Private Sub Compress(ByVal sPath As String, ByVal ZPath As String)
        Dim srcFile As String = sPath
        Dim dstFile As String = ZPath

        Dim fsIn As FileStream = Nothing
        ' will open and read the srcFile
        Dim fsOut As FileStream = Nothing
        ' will be used by the GZipStream for output to the dstFile
        Dim gzip As GZipStream = Nothing
        Dim buffer As Byte()
        Dim count As Integer = 0

            fsOut = New FileStream(dstFile, FileMode.Create, FileAccess.Write, FileShare.None)
            gzip = New GZipStream(fsOut, CompressionMode.Compress, True)

            fsIn = New FileStream(srcFile, FileMode.Open, FileAccess.Read, FileShare.Read)
            buffer = New Byte(fsIn.Length - 1) {}
            count = fsIn.Read(buffer, 0, buffer.Length)
            fsIn = Nothing

            ' compress to the destination file
            gzip.Write(buffer, 0, buffer.Length)
        Catch ex As Exception
            ' handle or display the error
            System.Diagnostics.Debug.Assert(False, ex.ToString())
            If gzip IsNot Nothing Then
                gzip = Nothing
            End If
            If fsOut IsNot Nothing Then
                fsOut = Nothing
            End If
            If fsIn IsNot Nothing Then
                fsIn = Nothing
            End If
        End Try

    End Sub
Question by:zillion_kamesh
  • 2
LVL 83

Expert Comment

ID: 38387584
Would you consider using a free 3rd party library?


Author Comment

ID: 38389710

I have found that the issue is happening based on the file size..

When i compress a file with the file size of 203 MB its working fine..

But the issue happens when am trying to compress a file that has the size of 2.55 GB.

Also the error flashing in the execution of following code..

buffer = New Byte(fsIn.Length - 1) {}

Hope this will be helpful to solve..

Note : I have to compress the file size of 20 GB to 50 GB.

LVL 83

Accepted Solution

CodeCruiser earned 500 total points
ID: 38390232
buffer = New Byte(fsIn.Length - 1) {}

Hope this will be helpful to solve..

Note : I have to compress the file size of 20 GB to 50 GB.

Good luck with creating a 50GB buffer :-)

Try with a 3rd party library or try using 7zip on command line.

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question