public void AsyncWriteDataBase() { var spName = ""; while (true) { try { var jsonText = RedisHelper.BlockingPopItemFromList("async_write_list"); var o = (JObject)JsonConvert.DeserializeObject(jsonText); if (o["need_newcache"].ToString() != "0") continue; spName=o["action"].ToString(); var jObject = o["paras"]; var paras = new MySqlParameter[jObject.Children().Count()]; var count = 0; foreach (JProperty item in jObject.Children()) { if (item.Value.ToString().Length >=1024) { paras[count] = new MySqlParameter(item.Name, MySqlDbType.MediumText); //var bytes = System.Text.Encoding.UTF8.GetBytes(item.Value.ToString()); //paras[count].Value = bytes; //如果下面的代码不行,试试上面注释掉的代码 paras[count].Value = item.Value.ToString(); } else { paras[count] = new MySqlParameter(item.Name, MySqlDbType.VarChar, 1024); paras[count].Value = item.Value; } count++; } SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, CommandType.StoredProcedure, spName, paras); Program.myFrm.SetTextMessage("成功写入异步数据库记录,调用的存储过程:" + spName, 3); } catch (Exception err) { Program.myFrm.SetTextMessage("写入异步数据库记录失败,调用的存储过程:" + spName+",错误原因:"+err, 3); } } }