从超过25MB的数据库中重新获取单个记录会导致OutOfMemoryException [英] Retriving single record from database exceeding 25MB causes OutOfMemoryException

查看:76
本文介绍了从超过25MB的数据库中重新获取单个记录会导致OutOfMemoryException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

从我们的电子邮件数据库中选择一条记录时遇到问题。

记录超过25MB(估计可能更多)大小,每当我尝试从上下文中获取它时,它会抛出一个OutOfMemoryException。

遗憾的是,NoTracking在这种情况下没有选项以避免第二个副本。



应用程序将电子邮件复制到存档数据库,在处理和重新创建上下文之前,我已经将批处理大小设置为每个上下文1条记录(使用语句)







这是相关函数的存根:



Hi all,
I am running into a problem when selecting a single record from our email database.
The record is over 25MB (estimated, probably more) in size and every time I try to get it from the context it throws an OutOfMemoryException.
NoTracking is unfortunately no option in this case in order to avoid the second copy.

The application copies emails to an archive database and I already set the batch size to 1 record per context before disposing and recreating the context (using statement)



Here is a stub for the function in question:

using (EmailDataEntities context = ContextFactory.GetEmailDataEntities())
{
    using (EmailArchiveDataEntities contextArchive = visualbooking.EmailArchiveDataContext.ContextFactory.GetEmailArchiveDataEntities())
    {
        foreach (long id in idList)
        {
            try
            {
                EmailDataContext.Model.tblEMailPostBox oDataEmail = context.tblEMailPostBox.FirstOrDefault(f => f.id == id);

                // copy the data here
                            

                // deleting original email


                // saving both contexts


                // Accepting all changes


            }
            catch (Exception ex)
            {
                // logging exception
            }
        }
    }
}







.FirstOrDefault()部分抛出异常,复制和保存在所有情况下都有效,除非是大记录。

现在我刚跳过记录。可以在数据库中手动复制它,但我想知道导致问题的背景......或者如果有任何记录的限制......




有没有办法获得记录,无论其大小?

或者有解决方法吗?



非常感谢任何帮助,

有一个美好的一天

Andy




The exception is thrown in the .FirstOrDefault() part, copying and saving is working in all cases except in the case of the big record.
Right now I just skipped the record. It is possible to copy it manually in the database, but I'd like to know about the background causing the problem... or the limits of records if there are any...


Is there a way to get the record regardless of its size?
Or is there a workaround?

Any help is kindly appreciated,
have a great day
Andy

推荐答案

这篇关于从超过25MB的数据库中重新获取单个记录会导致OutOfMemoryException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆