<p>When making changes using <code>SubmitChanges()</code>, LINQ sometimes dies with a <code>ChangeConflictException</code> exception with the error message <code>Row not found or changed</code>, without any indication of either the row that has the conflict or the fields with changes that are in conflict, when another user has changed some data in that row.</p>

<p>Is there any way to determine which row has a conflict and which fields they occur in, and also is there a way of getting LINQ to ignore the issue and simply commit the data regardless?</p>

<p>Additionally, does anybody know whether this exception occurs when <em>any</em> data in the row has changed, or only when data has been changed in a field that LINQ is attempting to alter?</p>

[{'answer_id': 32703, 'author': 'Greg Hurlman', 'author_id': 35, 'author_profile': 'https://Stackoverflow.com/users/35', 'pm_score': 2, 'selected': False, 'text': "<p>I've gotten this error in a circumstance completely unrelated to what the error message describes.</p>\n\n<p>What I did was load a LINQ object via one DataContext, and then tried to SubmitChanges() for the object via a different DataContext - gave this exact same error.</p>\n\n<p>What I had to do was call DataContext.Table.Attach(myOldObject), and then call SubmitChanges(), worked like a charm.</p>\n\n<p>Worth a look, especially if you're of the opinion that there really shouldn't be any conflicts at all.</p>\n"}, {'answer_id': 32705, 'author': 'TheSmurf', 'author_id': 1975282, 'author_profile': 'https://Stackoverflow.com/users/1975282', 'pm_score': 6, 'selected': True, 'text': '<p>Here\'s a way to see where the conflicts are (this is an MSDN example, so you\'ll need to heavily customize):</p>\n\n<pre><code>try\n{\n    db.SubmitChanges(ConflictMode.ContinueOnConflict);\n}\ncatch (ChangeConflictException e)\n{\n    Console.WriteLine("Optimistic concurrency error.");\n    Console.WriteLine(e.Message);\n    Console.ReadLine();\n    foreach (ObjectChangeConflict occ in db.ChangeConflicts)\n    {\n        MetaTable metatable = db.Mapping.GetTable(occ.Object.GetType());\n        Customer entityInConflict = (Customer)occ.Object;\n        Console.WriteLine("Table name: {0}", metatable.TableName);\n        Console.Write("Customer ID: ");\n        Console.WriteLine(entityInConflict.CustomerID);\n        foreach (MemberChangeConflict mcc in occ.MemberConflicts)\n        {\n            object currVal = mcc.CurrentValue;\n            object origVal = mcc.OriginalValue;\n            object databaseVal = mcc.DatabaseValue;\n            MemberInfo mi = mcc.Member;\n            Console.WriteLine("Member: {0}", mi.Name);\n            Console.WriteLine("current value: {0}", currVal);\n            Console.WriteLine("original value: {0}", origVal);\n            Console.WriteLine("database value: {0}", databaseVal);\n        }\n    }\n}\n</code></pre>\n\n<p>To make it ignore the problem and commit anyway:</p>\n\n<pre><code>db.SubmitChanges(ConflictMode.ContinueOnConflict);\n</code></pre>\n'}, {'answer_id': 32708, 'author': 'vzczc', 'author_id': 224, 'author_profile': 'https://Stackoverflow.com/users/224', 'pm_score': 4, 'selected': False, 'text': '<p>These (which you could add in a partial class to your datacontext might help you understand how this works:</p>\n\n<pre><code>public void SubmitKeepChanges()\n{\n    try\n    {\n        this.SubmitChanges(ConflictMode.ContinueOnConflict);\n    }\n    catch (ChangeConflictException e)\n    {\n        foreach (ObjectChangeConflict occ in this.ChangeConflicts)\n        {\n            //Keep current values that have changed, \n//updates other values with database values\n\n            occ.Resolve(RefreshMode.KeepChanges);\n        }\n    }\n}\n\npublic void SubmitOverwrite()\n{\n    try\n    {\n        this.SubmitChanges(ConflictMode.ContinueOnConflict);\n    }\n    catch (ChangeConflictException e)\n    {\n        foreach (ObjectChangeConflict occ in this.ChangeConflicts)\n        {\n            // All database values overwrite current values with \n//values from database\n\n            occ.Resolve(RefreshMode.OverwriteCurrentValues);\n        }\n    }\n}\n\npublic void SubmitKeepCurrent()\n{\n    try\n    {\n        this.SubmitChanges(ConflictMode.ContinueOnConflict);\n    }\n    catch (ChangeConflictException e)\n    {\n        foreach (ObjectChangeConflict occ in this.ChangeConflicts)\n        {\n            //Swap the original values with the values retrieved from the database. No current value is modified\n            occ.Resolve(RefreshMode.KeepCurrentValues);\n        }\n    }\n}\n</code></pre>\n'}, {'answer_id': 33482, 'author': 'liammclennan', 'author_id': 2785, 'author_profile': 'https://Stackoverflow.com/users/2785', 'pm_score': -1, 'selected': False, 'text': '<p>"and also is there a way of getting LINQ to ignore the issue and simply commit the data regardless?"</p>\n\n<p>You can set the \'Update Check\' property on your entity to \'Never\' to stop that field being used for optimistic concurrency checking.</p>\n\n<p>You can also use:</p>\n\n<pre><code>db.SubmitChanges(ConflictMode.ContinueOnConflict)\n</code></pre>\n'}, {'answer_id': 84185, 'author': 'Sam', 'author_id': 7021, 'author_profile': 'https://Stackoverflow.com/users/7021', 'pm_score': 2, 'selected': False, 'text': '<p>The error "Row not found or changed" also will appear sometimes when the columns or types in the O/R-Designer do not match the columns in the SQL database, especially if one column is NULLable in SQL but not nullable in the O/R-Designer.</p>\n\n<p>So check if your table mapping in the O/R-Designer matches your SQL database!</p>\n'}, {'answer_id': 12487195, 'author': 'Mark', 'author_id': 9976, 'author_profile': 'https://Stackoverflow.com/users/9976', 'pm_score': 2, 'selected': False, 'text': '<p>Thanks to @vzczc. I found the example you gave very helpful but that I needed to call SubmitChanges again after resolving. Here are my modified methods - hope it helps someone.</p>\n\n<pre><code>    /// &lt;summary&gt;\n    /// Submits changes and, if there are any conflicts, the database changes are auto-merged for \n    /// members that client has not modified (client wins, but database changes are preserved if possible)\n    /// &lt;/summary&gt;\n    public void SubmitKeepChanges()\n    {\n        this.Submit(RefreshMode.KeepChanges);\n    }\n\n    /// &lt;summary&gt;\n    /// Submits changes and, if there are any conflicts, simply overwrites what is in the database (client wins).\n    /// &lt;/summary&gt;\n    public void SubmitOverwriteDatabase()\n    {\n        this.Submit(RefreshMode.KeepCurrentValues);\n    }\n\n    /// &lt;summary&gt;\n    /// Submits changes and, if there are any conflicts, all database values overwrite\n    /// current values (client loses).\n    /// &lt;/summary&gt;\n    public void SubmitUseDatabase()\n    {\n        this.Submit(RefreshMode.OverwriteCurrentValues);\n    }\n\n    /// &lt;summary&gt;\n    /// Submits the changes using the specified refresh mode.\n    /// &lt;/summary&gt;\n    /// &lt;param name="refreshMode"&gt;The refresh mode.&lt;/param&gt;\n    private void Submit(RefreshMode refreshMode)\n    {\n        bool moreToSubmit = true;\n        do\n        {\n            try\n            {\n                this.SubmitChanges(ConflictMode.ContinueOnConflict);\n                moreToSubmit = false;\n            }\n            catch (ChangeConflictException)\n            {\n                foreach (ObjectChangeConflict occ in this.ChangeConflicts)\n                {\n                    occ.Resolve(refreshMode);\n                }\n            }\n        }\n        while (moreToSubmit);\n\n    }\n</code></pre>\n'}, {'answer_id': 54920592, 'author': 'Herman Van Der Blom', 'author_id': 2111313, 'author_profile': 'https://Stackoverflow.com/users/2111313', 'pm_score': 0, 'selected': False, 'text': '<p><strong>row not found or changed is most of times a concurrency problem</strong></p>\n\n<p>If a different user is changing the same record those errors popup because the record is already changed by that other user. So when you want to eliminate those errors you should handle concurrency in your application. If you handle concurrency well you won\'t get these errors anymore. The above code samples are a way to handle concurrency errors. Whats missing is that in case of a concurrency error you should put a <code>refresh</code> variable in those methods so when <code>refresh</code> is <code>true</code> the data needs to be refreshed on screen after the update so you will also see the update made by the other user.</p>\n\n<pre><code>    /// &lt;remarks&gt;\n    ///     linq has optimistic concurrency, so objects can be changed by other users, while\n    ///     submitted keep database changes but make sure users changes are also submitted\n    ///     and refreshed with the changes already made by other users.\n    /// &lt;/remarks&gt;\n    /// &lt;returns&gt;return if a refresh is needed.&lt;/returns&gt;\n    public bool SubmitKeepChanges()\n    {\n        // try to submit changes to the database.\n        bool refresh = false;\n        try\n        {\n            base.SubmitChanges(ConflictMode.ContinueOnConflict);\n        }\n\n        /* \n         * assume a "row not found or changed" exception, if thats the case:\n         * - keep the database changes already made by other users and make sure\n         * - this users changes are also written to the database\n         */\n        catch (ChangeConflictException)\n        {\n            // show where the conflicts are in debug mode\n            ShowConflicts();\n\n            // get database values and combine with user changes \n            base.ChangeConflicts.ResolveAll(RefreshMode.KeepChanges);\n\n            // submit those combined changes again to the database.\n            base.SubmitChanges();\n\n            // a refresh is needed\n            refresh = true;\n        }\n\n        // return if a refresh is needed.\n        return refresh;\n    }\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/32649', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3394/']