Update is thorwing Row not found error RRS feed

  • Question



    I have written the below code.

    using (InventoryImportDataContext invImpDataContext = new InventoryImportDataContext(conString))


    Run run = invImpDataContext.Runs.Single(runObject => runObject.RunID == runID);

    run.Step = step;

    run.CurrentFileID = fileID;




    Here I am able to get the run and after updating the values before SubmitChanges() I am able to see the updated values in the Object. but When SubmitChanges is called I am getting the below error.


    ex = {"Row not found or changed."}


    StackTrace is StackTrace = "   at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)\r\n   at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)\r\n   at System.Data.Linq.DataContext.SubmitChanges()\r\n  


    Please let me know what I doing wrong.

    I have made UpdateCheck to Never for all properties except for the Primary Key.




    Thursday, May 29, 2008 11:09 AM

All replies

  • Hi Anandraj,


    I presume RunId is your primary key isn't it ? Do you have timestamp in your table ?


    I created a similar situation to yours but didnt get the same error:


    Code Snippet

    using (TempDbDataContext context = new TempDbDataContext())


    Customer c = context.Customers.Single<Customer>(cx => cx.CustomerId == 1);

    c.CustomerName = "sidar";





    That runs fine when I don't have timestamp columns for version. CustomerId is set to updatecheck.always and customername is to none.


    you can also give a try to continue on the conflict with the code below:


    Code Snippet




    Let us know if this doesn't help.
    Thursday, May 29, 2008 2:24 PM
  • Thanks Sidar.


    I have also created a Table with Customer as you said and I am getting the same error. I have also added the coflictMode in the SubmitChanges and got the exception in the Exception When I use

    RefreshMode.OverwriteCurrentValues Then no exception further but data is not updated.

    RefreshMode.KeepChanges Or RefreshMode.KeepCurrentValues throws same exception.


    I think the problem is not with coding. I am using VS2008 Express Edition and I have to use MDF file to design the class. But my code will access the Real Data base Server which is located in another server. I will use a Connection String to access this server.


    When ever I create a table I will create in both the places and use it. But one think which I don't understand is I am able to get the values from the Database but not able to update.


    Will the MDF File and Database will be a problem? Is there any way to map the DB (not the MDF file) from VS2008?








    Friday, May 30, 2008 6:14 AM
  • Sidar,


    I have also tried with Professional Edition instead of Express but still getting the same error. I have tried even in NorthWind Database but getting the same error. Here is the Query


      NWDataContext DB = new NWDataContext();

                Product prod = DB.Products.Single<Product>(p => p.ProductID == 3);

                prod.ProductName = "Testing";




    So my doubt is Database or Database connection? I have used the SQL Server Logins in the Connection String instead of Windows Authentications. I have given my Connection string below.


    <add name="InventoryImport.Properties.Settings.NorthwindConnectionString"

                connectionString="Data Source=ServerName;Initial Catalog=Northwind;User ID=sa;pwd=pwd"

                providerName="System.Data.SqlClient" />


    I am struck with this problem not able to proceed.

    Please let me know if you find any solution.





    Friday, May 30, 2008 9:48 AM
  • Hi Anandraj,


    Attaching an MDF file should not be a problem since it is just done in the connection string. But in the second example you are not attaching a mdf file, instead you are connecting to a database that is already there aren't you ?


    Please bear with me while I set up northwind here in work to see if I'll get the error or not (while having lunch Smile )

    Friday, May 30, 2008 9:57 AM
  • Hi Sidar,


    Thanks for Replying back.


    Now I have tried the same Products query in different DB and it worked. When I just changed the Connection String to the Old DB I started getting error.


    So it is problem with the DB. Now I don't know what might be the problem? Any Idea? Let me restart my server and let you know.





    Friday, May 30, 2008 10:19 AM
  • Hi Anandraj,


    I tested it with Northwind and not getting any exception like yours. May be if you can post a script creates a db that can reproduce the problem, or better a solution that reproduce that would do.


    Friday, May 30, 2008 10:38 AM
  • Hi Sidar,


    I have moved the DB toward another Machine and the same code started working. But I don't know why it is not working in that particular Box.


    Even Update Query generated is correct.


    UPDATE [dbo].[Customer]
    SET [CustomerName] = @p1
    WHERE [CustomerId] = @p0


    Do you have any idea how to find out the problem?  So that in future it will easy for me to fix it.





    Friday, May 30, 2008 11:51 AM
  • Hi Sidar,


    After rebooting the server also it is not working but same code is working in different Machine.

    Any Idea?


    How can I track the error?





    Friday, May 30, 2008 12:51 PM
  • Ok, Let me picture it.


    You have a code in machine A . And the same code in Machine B. They are pointing to the same database and using the same connection string, which points do Machine C.


    The code doesnt work in machine A but exactly the same code, with same version and binaries, and same connection string it is throwing a "row not found or changed" error.


    Is this the case ? Can you define it if this isn't true for you ? Is it the northwind db that this code is not working against, or it is your db ? If it is your db, can you provide the structure of it, I wonder if you use timestamps ?

    Friday, May 30, 2008 1:33 PM
  • Hi Sidar,


    Thanks for your continuous responses.


    Let me clearly state the problem.


    I have some code to udpate a table.


    Customer cust = DB.Customers.Single(custObject => custObject.CustomerID== ID);

    Cust.CustomerName = Name;



    The table strucutre is as below. (Machine A)


    CREATE TABLE [dbo].[Customer](

    [CustomerId] [int] NOT NULL,

    [CustomerName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL

    ) ON [PRIMARY]


    I was getting some error like "Row not found". Then I tried to update some other table in Northwind (Machine A). there also I got the same error. When I changed the Database server to some other machine (Machine B) the same code started working. then I came to know there is no problem with my code. Then Restarted my Machine A to check whether the problem with the Database or not. But even after restarting it was throwing the same error.


    I think there is no problem with the code as well as no problem with the Database but problem with SQL Server. so Is there any way to track it? Like looking into the systemMessage in master DB? Any other to track it?


    In future if I get the same problem then I should be able to fix it.





    Monday, June 2, 2008 5:15 AM
  • Hi Anandraj,


    What I suspect from your table definition that has a latin collation is that it can be a problem with the regional settings on box A and box B can be different. On the other hand, to track down the problem: If you have sql profiler, you can see what queries are executed with what parameters, then with query analyzer, or try to connect to machine A with and execute same statement and see if it succeeds.







    Monday, June 2, 2008 12:12 PM
  • Hi Sidar,


    Even in the Machine B where it works has the same Table with Latin collation. I think the Database went to some state where it is giving error in all the databases in that SQL Server.

    Is there any way to track the state of the SQL Server?


    Even I have deleted the tables and recreated. Still it is throwing the same error.





    Tuesday, June 3, 2008 11:04 AM
  • Hi Anandraj,

    What are the differences between machine a & b ? Are their Cultural Settings, places in the network,sql version etc the same ?

    Is LINQ throwing the same exception on the other databases or tables?  or is it just this one ?

    Did you have a chance to turn the profiler on and monitor the statements flowing ?

    Tuesday, June 3, 2008 11:14 AM
  • Basically there should not be any difference between the two server coz these are the Development and Testing servers for one of the project. And the SQL Generated is


    UPDATE [dbo].[Customer]
    SET [CustomerName] = @p1
    WHERE [CustomerId] = @p0


    If you can tell me how to get the other informations like Cultural Settings etc. I will find out and send you the details.


    I have tried the LINQ Query in Northwind Database also. Still it is throwing error in Machine A but the same Query is working in Machine B. That is the reason I said there is a possibility for SQL Server to go some strange state.

    Is there any way to debug or trap this error in SQL Server.




    Tuesday, June 3, 2008 12:08 PM
  • By Cultural Settings I mean the regional info section on the control panel of the computer.


    The SQL you copied is from DataContext's log appearantly. From a profiler tool you can get the exact query with the paramaters. You need to have all the transaction with all the selects (that "single" performs) and run it in query analyzer to see if it succeeds.


    If it gets through, then the error is in application tier meaning that there is no error in SQL server to trap.


    If you can write a very simple ADO.NET application, that executes the same statement that you'll copy from the profiler with exactly the same parameters, I wonder if you'll get an error or not. Then we will see if it is a LINQ related issue or a general thing.




    Tuesday, June 3, 2008 1:39 PM

    Hi Sidar,


    Here is the SQL Copied from the Profiler and when I executed the Query in the Query Analyser it works. here is the Query.


    exec sp_executesql N'UPDATE [dbo].[Customer]
    SET [CustomerName] = @p1
    WHERE [CustomerId] = @p0', N'@p0 int,@p1 varchar(7)', @p0 = 1, @p1 = 'Ambrose'


    But Still I am getting the error in the Front End. What is the next step to track it.




    Wednesday, June 4, 2008 12:44 PM
  • Hi Sidar,


    I have tried the ExecuteCommand as below


    partial void UpdateCustomer(Customer instance)


    ExecuteCommand(string.Format("Update Customer Set CustomerName='Modified Finally' Where CustomerId={0}",instance.CustomerId));



    Then it started working. Is there any idea what was the problem?




    Friday, June 6, 2008 11:35 AM
  • After doing that the former code started working ? then it can be some changes done at that point of time to that row, but now since it is refreshed it doesn't throw it.


    I can't think anything further than 2 pages, i am about to hit the limits and start thinking about quantum physics to justify the problem Smile

    Friday, June 6, 2008 6:42 PM
  • Are you still getting the "Row not found error" or a different one now?




    Tuesday, June 10, 2008 10:55 PM

    Hi Amien,


    I am still getting the same error in that particular SQL Server(Machine A). The problem here is I am getting the same error in all the databases in that server. If I point to some other SQL Server (Machine B) then I am NOT getting the error.


    But If I add the ExecuteCommand in the UpdateCustomer (Machine A) then it is not throwing any error.


    Any Clue?






    Wednesday, June 11, 2008 5:16 AM