System.OutOfMemoryException - When Entity Framework is querying very large data of type Varbinary

1

I'm trying to query a varbinary field that contains a 1.2 Gb file, using Entity Framework . See below:

Test database

CREATE TABLE [dbo].[BIGDATA](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[BIGDATA] [varbinary](max) NULL, CONSTRAINT [PK_BIGDATA] PRIMARY KEY CLUSTERED ([id] ASC) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY]

Test data (any 1 Gb file)

INSERT INTO [dbo].[BIGDATA]
       ([BIGDATA])
 VALUES
       ((SELECT BulkColumn FROM OPENROWSET(BULK N'C:\BigTest.txt', SINGLE_BLOB) AS Document))

Controller to download the file

public FileResult Download()
{
    try
    {
        var context = new Models.ELOGTESTEEntities();
        var idArquivo = Convert.ToInt32(1);
        //The problem is here, when trying send command to sql server to read register
        var arquivo = (from item in context.BIGDATA
                           where item.id.Equals(idArquivo)
                           select item).Single();
        var mimeType = ".txt";              

        byte[] bytes = System.Text.Encoding.GetEncoding("iso-8859-8").GetBytes("BigTest.txt");
        return File(arquivo.BIGDATA1, mimeType, System.Text.Encoding.UTF8.GetString(bytes));
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

I can normally query on SQL Server with this SQL:

Select * From BigData

But in Entity Framework (or command with ADO ) I get this error (exception):

  

System.OutOfMemoryException

How to solve this?

    
asked by anonymous 07.07.2014 / 16:52

1 answer

0

I got the answer in stakoverflow in English. Follow the link below. Thank you.

.OutOfMemoryException - When Entity Framework is querying a too big data of Varbinary type

    

08.07.2014 / 04:40