G
Guest
I have a 31gb file that was exported from a unix box. I was trying to
bulkinsert it into sql but there seems to be something wrong with the file.
In order to isolate the issue I have tried splitting it into smaller files.
I get an out of memory on the 7th chunk of 10,000,000 lines using the code
below. The exe only seems to be consuming about 20Mb of memory. I have
tried several techniques but all yield the same results. Any suggestions?
I know the best answer is to not have a 31gb text file to begin with but
then I have to deal with the unix guys knocking windows inabilities.
Sub processfile(ByVal ReadFile As String)
Dim oread As IO.StreamReader
Dim owrite As IO.StreamWriter
Dim x As Int32
Dim readline As String
oread = IO.File.OpenText(ReadFile)
owrite = IO.File.CreateText("c:\output\" &
System.IO.Path.GetFileName(ReadFile) & "_0")
While oread.Peek <> -1
readline = oread.ReadLine
owrite.WriteLine(readline)
x = x + 1
If x Mod 10000000 = 0 Then
owrite.Close()
owrite.Dispose()
owrite = IO.File.CreateText("c:\output\" &
System.IO.Path.GetFileName(ReadFile) & "_" & (x / 10000000).ToString)
End If
If x Mod 1000000 = 0 Then
owrite.Flush()
oread.DiscardBufferedData()
TextBox1.Text = x
TextBox1.Refresh()
End If
End While
End Sub
bulkinsert it into sql but there seems to be something wrong with the file.
In order to isolate the issue I have tried splitting it into smaller files.
I get an out of memory on the 7th chunk of 10,000,000 lines using the code
below. The exe only seems to be consuming about 20Mb of memory. I have
tried several techniques but all yield the same results. Any suggestions?
I know the best answer is to not have a 31gb text file to begin with but
then I have to deal with the unix guys knocking windows inabilities.
Sub processfile(ByVal ReadFile As String)
Dim oread As IO.StreamReader
Dim owrite As IO.StreamWriter
Dim x As Int32
Dim readline As String
oread = IO.File.OpenText(ReadFile)
owrite = IO.File.CreateText("c:\output\" &
System.IO.Path.GetFileName(ReadFile) & "_0")
While oread.Peek <> -1
readline = oread.ReadLine
owrite.WriteLine(readline)
x = x + 1
If x Mod 10000000 = 0 Then
owrite.Close()
owrite.Dispose()
owrite = IO.File.CreateText("c:\output\" &
System.IO.Path.GetFileName(ReadFile) & "_" & (x / 10000000).ToString)
End If
If x Mod 1000000 = 0 Then
owrite.Flush()
oread.DiscardBufferedData()
TextBox1.Text = x
TextBox1.Refresh()
End If
End While
End Sub