C#和MySQL报Fatal error encountered during command execution的问题

做一个C#连接MySql课程小实验的时候遇到的一个bug。
Fatal error encountered during command execution的意思是:命令执行过程中遇到致命错误

错误信息
后来努力搜索,得出了解决方案。

原因:因为在sql语句中使用了自定义参数

string sql = "INSERT INTO student VALUES(@no,@pwd,@name,@sex,@grade_id,@phone_num,@address,@borndate,@email)";

所以……
需要在连接的URL内加上Allow User Variables=True,完美解决。
这样:

private static string SQL_URL = "server=localhost;user id=【你的账号】;password=【你的密码】;database=【连接的数据库名】;Port=3306;CharSet=gb2312;Allow User Variables=True";

连接数据库url的学问很深啊,除了平常的乱码问题,怎么也没想到这个错误会是url的问题。

猜你喜欢

转载自blog.csdn.net/qq_31407459/article/details/89148854