Bug #17344 Concurrency violation exception thrown when updating float and double columns
Submitted: 13 Feb 2006 17:28 Modified: 5 May 2006 9:53
Reporter: Brian Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:1.0.7 OS:Windows (XP Pro)
Assigned to: CPU Architecture:Any

[13 Feb 2006 17:28] Brian
Description:
I am using MySQL Connector.NET 1.0.7 to connect to MySQL 5 in Visual Studio 2005 (.NET 2.0). Doing an update of a floating point or double column causes a concurrency violaion to be thrown ("Updated 0 rows of the expected 1"). This can be worked around by using the Decimal data type, but that is really irritating. 

How to repeat:
To get the error, load the following table into a DataSet (m_ds), change the base currency using the function, and then update the database. You'll get a concurrency error.

CREATE TABLE Currencies 
(
	IDENT 			INT NOT NULL,
	Nom 			VARCHAR(32) not null,
	Symbol			VARCHAR(4),
	Exchange_Rate	   REAL not null,
	Base                    TINYINT(1) not null,
	CONSTRAINT PK_DEVISES PRIMARY KEY (IDENT),
);

INSERT INTO Currencies (IDENT, Nom, Symbol, Exchange_Rate, Base) VALUES (0,'Franc Suisse','CHF',1.00,1);
INSERT INTO Currencies (IDENT, Nom, Symbol, Exchange_Rate, Base) VALUES (1,'Dollar Australien','$',1.0481,0);
INSERT INTO Currencies (IDENT, Nom, Symbol, Exchange_Rate, Base) VALUES (2,'Euro','€',0.6455,0);
INSERT INTO Currencies (IDENT, Nom, Symbol, Exchange_Rate, Base) VALUES (3,'Pound','£',0.4428,0);
INSERT INTO Currencies (IDENT, Nom, Symbol, Exchange_Rate, Base) VALUES (4,'Yen Japonnais','¥',91.6227,0);
INSERT INTO Currencies (IDENT, Nom, Symbol, Exchange_Rate, Base) VALUES (5,'Dollar US','$',0.7904,0);

public bool SetBase(int Ident)
		{		
			try 
			{
				DataRow newBase = m_ds.Tables[0].Rows.Find(Ident);
				double ncv = Convert.ToDouble(newBase[3]);
                foreach (DataRow dr in m_ds.Tables[0].Rows)
                {
                    if (dr != newBase)
                    {
                        dr[4] = Convert.ToDouble(dr[3]) / ncv;
                        if (Convert.ToBoolean(dr[4])) { dr[4] = 0; };
                    }
                }
				newBase[3] = 1.0; 
				newBase[4] = 1;
			}
			catch (System.Exception exception)
            {
                string err = exception.Message;
                return false; 
            }
			return true;
		}

Suggested fix:
?????????????
[28 Feb 2006 0:59] [ name withheld ]
That error ocures even if a cell (of type float or double) was not changed but another cell in that row was changed.
[1 Mar 2006 9:27] [ name withheld ]
How to fix:

CommandBuilder.cs line 339, exchange with:

if (true != (bool)row["IsKey"] && true != (bool)row["IsUnique"])
[5 Apr 2006 9:53] Tonci Grgin
Thanks for your problem report. Can you please post sample project which demonstrates this behavior?
[5 May 2006 23:01] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".