在root账号中,可以正常调用存储过程.
换到common_user账号时,同一存储过程名调用出现问题.
追踪调试时出现:
SELECT command denied to user 'common_user'@'localhost' for table 'proc'
搜索解决方案:
MySqlConnection myconnection = new MySqlConnection("server=localhost;user id=common_user; password=***;database=testdb; Use Procedure Bodies=false;Charset=utf8;");
关键语句是:
Use Procedure Bodies=false;
在网上搜索本句含义:
Name : Use Procedure Bodies
Default : true
Description : Setting this option to false indicates that the user connecting to the database does not have the SELECT privileges for the mysql.proc (stored procedures) table. When to set to false, Connector/NET will not rely on this information being available when the procedure is called. Because Connector/NET will be unable to determine this information, you should explicitly set the types of the all the parameters before the call and the parameters should be added to the command in the exact same order as they appear in the procedure definition. This option was added in Connector/NET 5.0.4 and Connector/NET 1.0.10.
大体意思是说:
当设置时use procedure bodies=false,存储过程的参数需要与程序里的参数顺序一致.
还未结束.
在mysql官方.给出了这样设置会有一个BUG.
当然这样解决的办法还是有的.可以使用ODBC连接来实现.
这里不再详细说明.
附上.NET连接mysql的连接字符串网址(比较全面的连接归类):