Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   Filestreaming System.OutofMemoryException (http://www.go4expert.com/forums/filestreaming-systemoutofmemoryexception-t27982/)

sharon7 8Mar2012 21:05

Filestreaming System.OutofMemoryException
 
1 Attachment(s)
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 running this on a Windows 7, 64bit machine.

thanks for your help.

Sharon

sharon7 9Mar2012 02:36

Re: Filestreaming System.OutofMemoryException
 
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


All times are GMT +5.5. The time now is 03:48.