Description:
If running in a multithreaded environment, when there are concurrent threads running MySqlScripts with user-defined parameters, MySQL Connector throws "undefined parameter" error, even when AllowUserVariables is set to true and the parameter starts with a @.
Changing the code to output more information, we realize that in SerializeParameter.cs:
if (parmName.StartsWith("@", StringComparison.Ordinal)
&& ShouldIgnoreMissingParameter(parmName))
return false;
throw new MySqlException(
String.Format(Resources.ParameterMustBeDefined, parmName));
even when both conditions are true, the MySqlException is still thrown.
Was expecting this to be seamless since I requested that user-defined variables be accepted and am using the appropriate @ prefix where necessary.
This can only be if ShouldIgnoreMissingParameter is not accessing the current connection variable (where AllowUserVariables is true) in the following initial code block:
if (Connection.Settings.AllowUserVariables)
return true;
otherwise it would have to return false and not throw the exception. This actually outputs the variable name starting with @, which is why I think the problem should be in the Connection property. The problem is that within MySqlScript.Execute() this variable is always set to true:
bool allowUserVars = connection.Settings.AllowUserVariables;
connection.Settings.AllowUserVariables = true;
Furthermore, my connection string has "allowuservariables=true". So I am at a loss.
Thanks for your help!
André Morais
How to repeat:
For a very large volume of information in the following format:
val1,val2
where val1 and val2 are related varchar values, have several parallel threads using the same connection string run the same SQL in the following format:
INSERT INTO Tbl_A(Col1) VALUES ('Val1');
SET @a = LAST_INSERT_ID();
INSERT INTO Tbl_B(Col2) VALUES ('Val2');
SET @b = LAST_INSERT_ID();
INSERT INTO Tbl_A_x_Tbl_B(Col1, Col2) VALUES (@a,@b);
Where 'Val1' and 'Val2' are specific values.
Suggested fix:
Lock the connection variable or whichever is causing the problem.
Description: If running in a multithreaded environment, when there are concurrent threads running MySqlScripts with user-defined parameters, MySQL Connector throws "undefined parameter" error, even when AllowUserVariables is set to true and the parameter starts with a @. Changing the code to output more information, we realize that in SerializeParameter.cs: if (parmName.StartsWith("@", StringComparison.Ordinal) && ShouldIgnoreMissingParameter(parmName)) return false; throw new MySqlException( String.Format(Resources.ParameterMustBeDefined, parmName)); even when both conditions are true, the MySqlException is still thrown. Was expecting this to be seamless since I requested that user-defined variables be accepted and am using the appropriate @ prefix where necessary. This can only be if ShouldIgnoreMissingParameter is not accessing the current connection variable (where AllowUserVariables is true) in the following initial code block: if (Connection.Settings.AllowUserVariables) return true; otherwise it would have to return false and not throw the exception. This actually outputs the variable name starting with @, which is why I think the problem should be in the Connection property. The problem is that within MySqlScript.Execute() this variable is always set to true: bool allowUserVars = connection.Settings.AllowUserVariables; connection.Settings.AllowUserVariables = true; Furthermore, my connection string has "allowuservariables=true". So I am at a loss. Thanks for your help! André Morais How to repeat: For a very large volume of information in the following format: val1,val2 where val1 and val2 are related varchar values, have several parallel threads using the same connection string run the same SQL in the following format: INSERT INTO Tbl_A(Col1) VALUES ('Val1'); SET @a = LAST_INSERT_ID(); INSERT INTO Tbl_B(Col2) VALUES ('Val2'); SET @b = LAST_INSERT_ID(); INSERT INTO Tbl_A_x_Tbl_B(Col1, Col2) VALUES (@a,@b); Where 'Val1' and 'Val2' are specific values. Suggested fix: Lock the connection variable or whichever is causing the problem.