GZipStream compress problem in windows 2008 server R2


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
Who is Participating?
CodeCruiserConnect With a Mentor Commented:
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.
Would you consider using a free 3rd party library?

zillion_kameshAuthor Commented:

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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.