Mysql connector C#

When trying to connect with C# mysql Connector it gave me Unknown database ‘mysql’ , How shoul we fix this issue , we almost tried all versions?

NuGet Gallery | MySql.Data 8.1.0 is the package to use. Do you have a sample GitHub repo with reproduction steps including the SQL file to instantiate the database?

both the offical of mySql and the one i am using not workin ( when passwing paramter to stored procedire, if i am calling procedure without parameter it will work normally)

here is the github repo

https://github.com/adelemam/MemSql

Thanks for the repro github repo. The code looks good (assuming you’ve specified the correct ip, user, and pass.) Clarifying, are you saying the get table works and the sproc works without parameters, but passing parameters doesn’t work? I notice you’re using MySQL version 0.62.0 and the current version is 8.0.20. Any reason you need this legacy version? My guess is it’s a bad interaction between Dapper and MySQL. Try it without Dapper and see if it works as expected.

Ok I have changed code now to following ( I pushed it )
using connector you sent ( official connector , last version 8.0.20 )
removed dapper and worked with Ado command

when tried inline query , it worked normally , when tried procedure with paramater it gave same error with dapper)

{MySql.Data.MySqlClient.MySqlException (0x80004005): Unknown database ‘mysql’
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.SchemaProvider.GetProcedures(String[] restrictions)
at MySql.Data.MySqlClient.ISSchemaProvider.GetProcedures(String[] restrictions)
at MySql.Data.MySqlClient.ISSchemaProvider.GetSchemaInternal(String collection, String[] restrictions)
at MySql.Data.MySqlClient.SchemaProvider.GetSchema(String collection, String[] restrictions)
at MySql.Data.MySqlClient.MySqlConnection.GetSchemaCollection(String collectionName, String[] restrictionValues)
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.GetParameters(String procName)
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.ExecuteReader()
at DapperMemsqlConsole.Program.Main(String[] args) in /Users/ntime/Documents/Work/Learning/DapperMemsqlConsole/Program.cs:line 21}

@robrich , so i am providing a basic feature with few line of code ( not complications and very basic ) , does this mean that there is a bug in MemSql or that it doesn’t support c# or there is no supported provider yet?, as we are taking strategical decision to migrate to Memsql and this will change our plan :frowning:

Give me a few days to produce a code sample. I’m speaking at two conferences this week, so time is limited. I’ve done exactly what you’re looking for previously though, so I’m confident we can get it solved.

thanks a lot , I will be waiting

I created a PR into your repo adding checkparameters=false to the connection string. MySQL has a mysql database with schema information, but MemSQL does not. This disables the driver validation to make sure the parameters exist before calling the stored procedure.

thanks a lot , it worked :slight_smile:

So glad it worked. Does Dapper now work as expected with this change in connection string? Is the app you’re building open-source?

@robrich , yes dapper worked properly but we have another issue with Return Parameters , it doesn’t work at all , we only doing something like this and it gaves error:
var p = new DynamicParameters();
p.Add("$Id", 5, dbType: DbType.Int32, direction: ParameterDirection.ReturnValue);
var testTableList1 = connection.Execute(“sp_ntime_TestR”, p, commandType: CommandType.StoredProcedure);
// Console.WriteLine(“Hello World!”);
var returnValue = p.Get("$Id");

and it gaves strange exception , Do you have any idea??

and not project we are working on is not open sourced yet >

Not sure. MemSQL doesn’t support out parameters, so I’ve generally shied away from return parameters as well, choosing to select the return value as a second dataset.

thanks, we already did so

1 Like