小编Kap*_*ija的帖子

使用Entity Framework的System.OutOfMemoryException?

我正在尝试使用Entity框架保存数十万条记录.保存几十万条记录后,我得到以下错误:

:为System.OutOfMemoryException

我的代码

  foreach (BibContent objbibcontents in lstBibContent)
        {
            db.BibContents.AddObject(objbibcontents);
            c = c + 1;
            if (c == 1000)
            {
                db.SaveChanges();
                c = 0;
            }
        }
Run Code Online (Sandbox Code Playgroud)

我注意到在保存了1000条记录后,我的数据库没有覆盖另外1000条记录.它将它们添加到我的dbcontext中.

我在1000条记录后创建了一个新实例,但我的数据库仍然具有上一个对象的数据.看我的代码

   foreach (var objbibcontents in lstBibContent)
            {
                vibrantEntities db1 = new vibrantEntities(szConStr);
                lstBibCon.Add(objbibcontents);
                // db.BibContents.AddObject(objbibcontents);
                c = c + 1;
                if (c == 1000)
                {
                    foreach (BibContent bibobject in lstBibCon)
                    {
                        db1.BibContents.AddObject(bibobject);
                    }
                    lstBibCon.Clear();
                    db1.SaveChanges();
                    c = 0;
                    flag = 1;
                }
            }
Run Code Online (Sandbox Code Playgroud)

entity-framework entity-framework-4.1

9
推荐指数
1
解决办法
8877
查看次数

我的Windows服务没有运行数据库连接的exe文件?

我创建了一个Windows应用程序.当我手动执行我的可执行文件时,它工作正常,但是当我使用Windows服务运行我的exe时,它显示提供失败错误.我正在使用实体框架.实体框架有什么问题吗?

这是我的代码:

   private void Threadfun()
    {
        try
        {               
            System.Diagnostics.Process.Start(@"D:\V-Tec\bin\Debug\VibrantIndexerForm.exe");
            if (System.IO.File.Exists(@"D:\VibrantIndexerSetup\MarcExport1.txt"))
            {
            }
            else
            {
                System.IO.File.Create(@"D:\VibrantIndexerSetup\MarcExport1.txt").Dispose();
            }

            System.IO.File.WriteAllText(@"D:\VibrantIndexerSetup\MarcExport1.txt", System.DateTime.Now.ToString());
            System.Threading.Thread.Sleep(100);
        }
        catch (Exception ex)
        {
        }     
    } 

 private void time_Elapsed(object sender, ElapsedEventArgs e)
    {

        m_thread = new System.Threading.Thread(new System.Threading.ThreadStart(Threadfun));
        if (m_thread.IsAlive)
        {
        }
        else
        {
            m_thread.Start();
        }
    }

    protected override void OnStart(string[] args)
    {
        if (time.Enabled == false)
        {    
            time.Elapsed += new ElapsedEventHandler(time_Elapsed);
            time.Interval = 2000;
            time.Enabled = true;
        }
    }

    protected override void OnStop()
    {
        time.Enabled = false;  
    } …
Run Code Online (Sandbox Code Playgroud)

c# windows windows-services winforms entity-framework-4

7
推荐指数
1
解决办法
453
查看次数