Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filestreaming System.OutofMemoryException

Status
Not open for further replies.

sharonchapman7

Programmer
Aug 31, 2011
45
US
Hi,
I am getting an System.OutofmemoryException when using Filestream to load zip file. the file is 521MB. My code is:

//Insert using Filestream, file into SQL Server Table
private void btnInsert_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDlg = new OpenFileDialog();
openFileDlg.InitialDirectory = Directory.GetCurrentDirectory();
if (openFileDlg.ShowDialog() == DialogResult.OK)
{
FileInfo fi = new FileInfo(openFileDlg.FileName);
FileStream fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read);
BinaryReader rdr = new BinaryReader(fs);
byte[] fileData = rdr.ReadBytes((int)fs.Length);
rdr.Close();
fs.Close();

My program dies on this line: byte[] fileData = rdr.ReadBytes((int)fs.Length);
i have also attached the detail for the System.OutofMemoryException. I am runing this on a Windows 7, 64bit

machine.

thanks for your help.

Sharon
 
Hi,

As I mentioned I have a machine that has 8 GB of memory. I had to shut down my machine to take it home last night.

When I tried to load the file again today it loaded with no problem. Normally I will only be loading one file at a

time, but in this case I was testing my Development database and was loading 28 files one right after the other.



Sharon
 
Out of Memory Exceptions can sometimes be misleading... OoM exceptions often has very little to do with the amount of RAM you have. Depending on what you had open, memory leaks, etc you may have run into a point where the heap wasn't able to handle it.

Walt
Ciber/NES
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top