问题:
在执行下边的语句时,reader报错:未将对象引用设置到对象的实例,或者 Fatal error encountered during data read
或者Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding
_MysqlConnStr = "server = " + MysqlIP
+ "; database =" + MysqlDatabase
+ "; user id = " + MysqlUserName
+ "; password = " + MysqlPassword
+ ";pooling=true;CharSet=utf8;port=3306;SslMode = none;AllowLoadLocalInfile=true;allow zero datetime=true";
_MysqlCmd = "SELECT * FROM t_data";
using (var Reader = MySqlHelper.ExecuteReader(connection, _MysqlCmd))
{
while (Reader.Read())
{
//******
}
}
此时尝试一下是否为连接已断开,将连接超时设置的长一些
default command timeout=999999
在语句中的写法:
_MysqlConnStr = "server = " + MysqlIP
+ "; database =" + MysqlDatabase
+ "; user id = " + MysqlUserName
+ "; password = " + MysqlPassword
+ ";pooling=true;CharSet=utf8;port=3306;SslMode = none;AllowLoadLocalInfile=true;allow zero datetime=true;default command timeout=999999";
_MysqlCmd = "SELECT * FROM t_data";
using (var Reader = MySqlHelper.ExecuteReader(connection, _MysqlCmd))
{
while (Reader.Read())
{
//******
}
}
参考https://stackoverflow.com/questions/2546115/mysql-exception-fatal-error-encountered-during-data-read