Bug #77120 MySQLScript throws undefined parameter even with AllowUserVariables
Submitted: 21 May 2015 14:22 Modified: 22 Feb 2016 10:35
Reporter: André Morais Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:6.8.4, 6.9.6, 6.9.8 OS:Microsoft Windows
Assigned to: CPU Architecture:Any
Tags: AllowUserVariables, mysqlscript, SerializeParameter, Undefined parameter

[21 May 2015 14:22] André Morais
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.
[22 May 2015 6:43] Chiranjeevi Battula
Hello André Morais,

Thank you for the bug report.
Verified this behavior on Visual Studio 2013 (C#.Net) with  MySQL Connector/Net 6.9.6.

Thanks,
Chiranjeevi.
[22 May 2015 6:43] Chiranjeevi Battula
Error Message screenshot

Attachment: 77120.PNG (image/png, text), 124.35 KiB.

[22 Feb 2016 10:35] André Morais
Any plans to fix this problem soon?