Bug #99371 Cannot call stored procedures in databases whose name contains a period
Submitted: 27 Apr 2020 16:45 Modified: 7 May 2020 17:44
Reporter: Xavier Mawet Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:8.0.18, 8.0.20 OS:Any
Assigned to: CPU Architecture:Any

[27 Apr 2020 16:45] Xavier Mawet
Description:
The MySQL C# .NET connector does not support the execution of stored procedures in databases (schema) whose name contains one or more period(s).

Considering the schema `db_1.2.3.45678`, the connector doesn't escape (with quoted identifiers) the database/schema name when running the stored procedures, resulting in errors as follows:

MySql.Data.MySqlClient.MySqlException (0x80004005): Procedure or function '`2`' cannot be found in database '`db_1`'.
   at MySql.Data.MySqlClient.ProcedureCache.GetProcData(MySqlConnection connection, String spName)
   at MySql.Data.MySqlClient.ProcedureCache.AddNew(MySqlConnection connection, String spName)
   at MySql.Data.MySqlClient.ProcedureCache.GetProcedure(MySqlConnection conn, String spName, String cacheKey)
   at MySql.Data.MySqlClient.StoredProcedure.CheckParameters(String spName)
   at MySql.Data.MySqlClient.StoredProcedure.Resolve(Boolean preparing)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
   ...

The first dot in the schema name is interpreted as the separator between the schema name and the name of the stored procedure.

How to repeat:
1) Create a new schema (database) whose name contains one or more periods:

CREATE SCHEMA `db_1.2.3.45678` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

2) Create a stored procedure:

DROP PROCEDURE IF EXISTS MyStoredProcedure;

DELIMITER |

CREATE PROCEDURE MyStoredProcedure()
BEGIN
    -- stored procedure body
END |

DELIMITER ;

3) Try to call the stored procedure using the C# .NET connector:

using (MySqlConnection connection = new MySqlConnection(connectionString: "<connection string>"))
{
    // connecting to MySQL Server...
    connection.Open();
    // create command of type "stored procedure"
    MySqlCommand cmd = connection.CreateCommand();
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = "MyStoredProcedure"; // stored procedure name
    // execute the command (call the stored procedure)
    cmd.ExecuteNonQuery(); // Exception occurs here ...
}

Suggested fix:
The schema name should be escaped with quoted identifiers!

db_1.2.3.45678.MyStoredProcedure() should be `db_1.2.3.45678`.MyStoredProcedure()
[28 Apr 2020 8:25] MySQL Verification Team
Hello Xavier Mawet,

Thank you for the report and test case.

regards,
Umesh
[28 Apr 2020 15:09] Bradley Grainger
This may be a duplicate of bug #84220.
[29 Apr 2020 10:22] Xavier Mawet
Hi Bradley Grainger,

Before creating this case, I did a search and I also found the bug 84220 (https://bugs.mysql.com/bug.php?id=84220).

Although the two bugs are very similar, mine is about issues with dots in schema name, while the other is about issues with dots in procedure name. In both cases, escaping with quoted identifiers is probably the solution.

Regards,
Xavier Mawet
[7 May 2020 17:44] Christine Cole
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/NET 8.0.21 release, and here's the proposed changelog entry from the documentation team:

An error occurred when the name of a database or stored procedure
contained one or more period characters. Now, names with this format can
be used when the name is enclosed properly between grave accent (`)
symbols; for example, `db_1.2.3.45678`.

Thank you for the bug report.