首页 新闻 会员 周边 捐助

vs2019+mysql5.7的连接字符串报错问题

0
悬赏园豆:50 [已关闭问题] 关闭于 2022-10-19 21:39

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;

tea2007的主页 tea2007 | 初学一级 | 园豆:3
提问于:2022-10-19 17:04
< >
分享
所有回答(2)
0

config 应该是关键字,换个表名,

菜鸡adam | 园豆:209 (菜鸟二级) | 2022-12-23 16:11
0

I will try to find some software to prevent this error from appearing again. that's not my neighbor

sarausa | 园豆:208 (菜鸟二级) | 2024-04-17 12:23
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册