Filestreaming System.OutofMemoryException

Discussion in 'C#' started by sharon7, Mar 8, 2012.

  1. sharon7

    sharon7 New Member

    Joined:
    Feb 23, 2012
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    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
     

    Attached Files:

  2. sharon7

    sharon7 New Member

    Joined:
    Feb 23, 2012
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    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
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice