public static readonly string mysqlStr = "user id = root; server=127.0.0.1;password=111111;persistsecurityinfo=True;database=abcyy;allow user Variables=True";//连接字符串,连接字符串换过几个都不行,加allowPublicKeyRetrieval=true会报keyword not supported
//---------------------------------------------------------------------------------------------------------------------
DataTable dt_Temp;//临时表
//------------------------------------------------------------------------------------------------------------------------
dt_Temp = My_MySQL.getResults(My_MySQL.mysqlStr, "config");//一传config表就出错,换其它表没问题
public static DataTable getResults(string mysqlStr, string table)
{
lock (objReadMySQL)
{
try
{
using (MySqlConnection mysql = new MySqlConnection(mysqlStr))
{
using (MySqlCommand mySqlCommand = mysql.CreateCommand())
{
mySqlCommand.CommandText = "select * from " + table;
if (mysql.State != ConnectionState.Open)
mysql.Open();
MySqlDataReader mySqlDataReader =mySqlCommand.ExecuteReader();//出错语句,当传config表进来,执行此句就出错,
//--------------------------------------------------------------------------------------------------------------
报错内容如下:
ex {"Fatal error encountered attempting to read the resultset."} System.Exception {MySql.Data.MySqlClient.MySqlException}
//-------------------------------------------------------------------------------------------------------------
//********************************************************************************************
//---------------------------------------------------------------------------------------------------------
/*config表脚本,picture字段是放图片的,会不会问题出在这里.换其他没图的表就正常
Navicat Premium Data Transfer
Source Server : bs
Source Server Type : MySQL
Source Server Version : 50716
Source Host : localhost:3306
Source Schema : richfruits
Target Server Type : MySQL
Target Server Version : 50716
File Encoding : 65001
Date: 19/10/2022 17:11:48
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- Table structure for config
DROP TABLE IF EXISTS config
;
CREATE TABLE config
(
id
int(11) NOT NULL AUTO_INCREMENT,
picture
varchar(255) CHARACTER SET utf16 COLLATE utf16_general_ci NOT NULL COMMENT '设计界面图',
panelDesignWidth
int(4) NOT NULL COMMENT '设计界面大小',
panelDesignHeight
int(4) NOT NULL COMMENT '设计界面大小',
currformula
varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '当前',
config_date
datetime(0) NOT NULL COMMENT '日期',
masterPLC_ip
varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '主ip',
masterPLC_port
int(5) NULL DEFAULT NULL COMMENT '主端口',
masterPLC_station
int(3) NULL DEFAULT NULL COMMENT '主号',
labelTitle_text
varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '字符串',
PRIMARY KEY (id
) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '配置' ROW_FORMAT = Dynamic;
SET FOREIGN_KEY_CHECKS = 1;
config 应该是关键字,换个表名,