Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Fast Inserting Values with Linq in a database

Fast Inserting Values with Linq in a database

Scheduled Pinned Locked Moved LINQ
helpquestioncsharpdatabaselinq
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ezazazel
    wrote on last edited by
    #1

    Hi guys! Can anyone please help me with this: I have a sdf Database used by LINQ. It is used for error logging. If I have multiple Errors at the same time, logs.ErrorTables.InsertOnSubmit(table); throws an error stating, that this operation is not allowed while SubmitChanges() is still working. How can I avoid this? Here's my code:

    public void SetErrorMessage(ErrorMessage message)
    {
    if (logs == null)
    logs = new Logs(@"Data Source=Log\Logs.sdf;Persist Security Info=False;");

            ErrorTable table = new ErrorTable()
            {
                ErrorDate = message.Time,
                ErrorThrower = message.ErrorThrower,
                ErrorMessageText = message.ErrorMessageText,
                ResponsibleDev = message.ResponsibleDev,
                ErrorPriority = Convert.ToInt32(message.ErrorPriority)
            };
    
            
            logs.ErrorTables.InsertOnSubmit(table);
            logs.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict);
            
            
    
        }
    

    Thanks in advance!

    L 1 Reply Last reply
    0
    • E ezazazel

      Hi guys! Can anyone please help me with this: I have a sdf Database used by LINQ. It is used for error logging. If I have multiple Errors at the same time, logs.ErrorTables.InsertOnSubmit(table); throws an error stating, that this operation is not allowed while SubmitChanges() is still working. How can I avoid this? Here's my code:

      public void SetErrorMessage(ErrorMessage message)
      {
      if (logs == null)
      logs = new Logs(@"Data Source=Log\Logs.sdf;Persist Security Info=False;");

              ErrorTable table = new ErrorTable()
              {
                  ErrorDate = message.Time,
                  ErrorThrower = message.ErrorThrower,
                  ErrorMessageText = message.ErrorMessageText,
                  ResponsibleDev = message.ResponsibleDev,
                  ErrorPriority = Convert.ToInt32(message.ErrorPriority)
              };
      
              
              logs.ErrorTables.InsertOnSubmit(table);
              logs.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict);
              
              
      
          }
      

      Thanks in advance!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The problem looks like it's associated with recursive usage of the same DataContext instance during the SubmitChanges() execution in your code. Try to create a new context instance each time you need to save a log. Devart Team http://www.devart.com/dotconnect ADO.NET data providers for Oracle, MySQL, PostgreSQL, SQLite with Entity Framework and LINQ to SQL support

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups