Hi. I have a web application hosted on a webserver, done using Linq-to-sql. I have used the general Linq-to-SQL update statements, and when an update is done to a record from a single user, it updates without any problems. However, when many are using the
same update page at the same time, which uses the same data context, it shuffles by updating the wrong record requested by another user, rather than the original source. I am just using the Unique Record ID ro identify the updating record, and just use context.SaveChanges()
to commit the changes.
Can any one suggest what I am doing wrong here. As I have said, I am using Linq-to_SQL, I have used optimistic concurrency aswell.
hahs_m
Member
41 Points
59 Posts
Update issues when done simultaneously Linq-to-SQL
Nov 23, 2012 04:27 PM|LINK
Hi. I have a web application hosted on a webserver, done using Linq-to-sql. I have used the general Linq-to-SQL update statements, and when an update is done to a record from a single user, it updates without any problems. However, when many are using the same update page at the same time, which uses the same data context, it shuffles by updating the wrong record requested by another user, rather than the original source. I am just using the Unique Record ID ro identify the updating record, and just use context.SaveChanges() to commit the changes.
Can any one suggest what I am doing wrong here. As I have said, I am using Linq-to_SQL, I have used optimistic concurrency aswell.
Thanks
hahsm
eric2820
Contributor
2777 Points
1161 Posts
Re: Update issues when done simultaneously Linq-to-SQL
Nov 23, 2012 07:49 PM|LINK
It's impossible to diagnose your issue without seeing the code that you're having an issue with.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
hahs_m
Member
41 Points
59 Posts
Re: Update issues when done simultaneously Linq-to-SQL
Nov 24, 2012 03:06 AM|LINK
Here is a code sample which I am using to update.
public static bool UpdateRecord(Ledger_Brand RecordSet, int StaffID) { using (dbLedger db = new dbLedger()) { var updateRecord = (from e in db.Ledger_Brands where e.BrandID == RecordSet.BrandID select e).SingleOrDefault(); updateRecord.BrandName = RecordSet.BrandName; updateRecord.RecordStatus = RecordSet.RecordStatus; try { db.SubmitChanges(); FacilitatorRepository.InsertTransactionLog("Ledger_Brand", StaffID, 0, RecordSet.BrandID); } catch (ChangeConflictException) { foreach (ObjectChangeConflict obj in db.ChangeConflicts) { obj.Resolve(RefreshMode.KeepChanges); } } catch (Exception ex) { return false; throw; } } return true; }Thanks
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Update issues when done simultaneously Linq-to-SQL
Nov 24, 2012 08:04 AM|LINK
Hello hahs_m,
I think you can just set Confliction in the Submit method:
For more you can download the sample here:http://www.codeproject.com/Articles/38299/How-To-Handle-Concurrency-in-LINQ-to-SQL
eric2820
Contributor
2777 Points
1161 Posts
Re: Update issues when done simultaneously Linq-to-SQL
Nov 24, 2012 03:01 PM|LINK
What would happend if you allowed only one user at a time into that code?
Just how heavely is that method being called?
I would at least consider putting a Lock statment at the start of that method to limit it to 1 executaion at a time.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.