Fast Inserting Values with Linq in a database
-
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!
-
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!
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