gpt4 book ai didi

c# - mysql 查询在增加 'max_allowed_packet' 后被截断

转载 作者:行者123 更新时间:2023-11-30 23:11:04 25 4
gpt4 key购买 nike

我在 c# 中有一个存储过程,我向其中添加值然后执行:

        string query = "INSERT INTO equipment_parameter (parameter_group_name, version, operation_name, parameter_name, parameter_value, default, owner, date_created) VALUES(@parameter_group_name, @version, @operation_name, @parameter_name, @parameter_value, @default, @owner, @date_created)";    //stored procedure

//open connection
if (mySQLA.OpenConnection() == true)
{
//create command
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = mySQLA.getConnection();
cmd.CommandText = query;
cmd.Prepare();

//string
cmd.Parameters.AddWithValue("@parameter_group_name", eParam.ParameterGroupName);
//int
cmd.Parameters.AddWithValue("@version", eParam.Version);
//string
cmd.Parameters.AddWithValue("@operation_name", eParam.OperationName);
//string
cmd.Parameters.AddWithValue("@parameter_name", eParam.ParameterName);
//double
cmd.Parameters.AddWithValue("@parameter_value", eParam.ParameterValue);
//bool
cmd.Parameters.AddWithValue("@default", eParam.Default);
//string
cmd.Parameters.AddWithValue("@owner", eParam.Owner);
//DateTime
cmd.Parameters.AddWithValue("@date_created", eParam.DateCreated);

//Execute command
try
{
rowsCreated = cmd.ExecuteNonQuery(); //returns number of rows affected
}
catch (MySqlException es)
{
MessageBox.Show(es.Message, "Equipment Parameter Query Error: ");
}

当我运行这个程序时,它会尝试插入,然后我捕获到异常,它指出:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'default, owner, date_created) VALUES('object1', 1, 'Op1', 'object1', 10.01, 1, '' at line 1

我尝试执行的查询内容如下:

INSERT INTO equipment_parameter (parameter_group_name, version, operation_name, parameter_name, parameter_value, default, owner, date_created) VALUES('object', 1, 'Op1', 'object1', 10.01, false, 'James', '2013-10-30 09:00:54')

我已经将“max_allowed_pa​​cket”增加到 500M 并重新启动了服务器,尽管这没有任何效果。是否有其他我可以增加的缓冲区大小选项或者我的问题可能是什么?

最佳答案

在我对此感到困惑之后,我才意识到 default 是一个保留字。因此,它必须反引号:

[...] parameter_value, `default`, owner, date_created) [...]

关于c# - mysql 查询在增加 'max_allowed_packet' 后被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19688914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com