"Row not found or changed" Problem

Posted by winston schröder on Stack Overflow See other posts from Stack Overflow or by winston schröder
Published on 2010-04-07T14:03:19Z Indexed on 2010/04/07 19:13 UTC
Read the original article Hit count: 369

Filed under:
|
|

Hi there, I'm working on a SQL CE Database and get into the "Row nor found or changed" exception. The exception only occurs when I try to update. On the first Run after the insert it shows up a MemberChangeConflict which says, that my Column Created_at has in all three values (current, original, database) the same. But in a second attempt it doesn't appear anymore.

The DataContext is instanciated on Startup and freed on Exit of my Local(!) Application. I use a sqlmetal generated mapping and code file. In the map I added some Associations and set the timemstamp columns UpdateCheck property to Always while all other have the setting never. The Timestamp Column is marked as isVersion="true", the Id Column as Primary Key.

Since I don't dispose the datacontext I expected to be using implicit transaction. When I run the SubmitChanges Method within a TransactionScope.

Can anyone tell me how I can update the timestamp within the code ? I know about the Problems one has to deal with if you dispose the datacontext. So I decided not to do this since I use a Single User Local DB Cache File. (I did already use a version where I disposed the datacontext after every usage, but this version had a real bad performance and error rate, so I decided to choose the other variant.)

LibDB.Client.Vehicles tmp = null;
        try
        {
            tmp = e.Parameter as LibDB.Client.Vehicles;
            if (tmp == null) return;
            if (!this._dc.Vehicles.Contains(tmp))
            {
                this._dc.Vehicles.Attach(tmp);
            }
            this.ShowChangesReport(this._dc.GetChangeSet());                
            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    this._dc.SubmitChanges();
                    ts.Complete();
                }
                catch (ChangeConflictException cce)
                {
                    Console.WriteLine("Optimistic concurrency error.");
                    Console.WriteLine(cce.Message);
                    Console.ReadLine();
                    foreach (ObjectChangeConflict occ in this._dc.ChangeConflicts)
                    {
                        MetaTable metatable = this._dc.Mapping.GetTable(occ.Object.GetType());
                        LibDB.Client.Vehicles entityInConflict = (LibDB.Client.Vehicles)occ.Object;
                        Console.WriteLine("Table name: {0}", metatable.TableName);
                        Console.Write("Vin: ");
                        Console.WriteLine(entityInConflict.Vin);
                        foreach (MemberChangeConflict mcc in occ.MemberConflicts)
                        {
                            object currVal = mcc.CurrentValue;
                            object origVal = mcc.OriginalValue;
                            object databaseVal = mcc.DatabaseValue;
                            MemberInfo mi = mcc.Member;
                            Console.WriteLine("Member: {0}", mi.Name);
                            Console.WriteLine("current value: {0}", currVal);
                            Console.WriteLine("original value: {0}", origVal);
                            Console.WriteLine("database value: {0}", databaseVal);
                        }
                        throw cce;
                    }
                }

                catch (Exception ex)
                {
                    this.ShowChangeConflicts(this._dc.ChangeConflicts);
                    Console.WriteLine(ex.Message);
                }
            }
            this.ShowChangesReport(this._dc.GetChangeSet());

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about exceptions