未处理的类型为'System.ArgumentException'发生在System.Data.dll中

本文关键字:System Data dll 类型 未处理 ArgumentException | 更新日期: 2023-09-27 18:04:43

当我试图将插入值连接到我的数据库时,我遇到了标题中的错误。我的调试错误出现在:

using (var conn = new MySqlConnection(myConString))

下面是VS2013的错误:

系统。ArgumentException未处理HResult=-2147024809
消息=初始化字符串格式不符合规格从索引153开始。源=系统。数据
加:在System.Data.Common.DbConnectionOptions.GetKeyValuePair(字符串connectionString, Int32 currentPosition, StringBuilder缓冲区,布尔值useOdbcRules String&keyname String&keyvalue)System.Data.Common.DbConnectionOptions.ParseInternal(哈希表connectionString, Boolean buildChain, Hashtable同义词,Boolean firstKey)在System.Data.Common.DbConnectionOptions . .(字符串connectionString, Hashtable同义词,布尔值useodbrules)在System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(字符串值)MySql.Data.MySqlClient.MySqlConnectionStringBuilder . .男星(字符串connStr)在MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString(字符串值)在MySql.Data.MySqlClient.MySqlConnection . .男星(字符串connectionString)在MD5_Loader.MainForm。btn_Upload_Click(Object sender, EventArgs e) in d:'xxxx'MD5Loader'MD5 Loader'MainForm.cs:第43行在System.Windows.Forms.Control。OnClick (EventArgs e)在System.Windows.Forms.Button。OnClick (EventArgs e)在System.Windows.Forms.Button。OnMouseUp (MouseEventArgs mevent)在System.Windows.Forms.Control.WmMouseUp (Message&m,鼠标按钮,点击32下)在System.Windows.Forms.Control.WndProc (Message&米)在System.Windows.Forms.ButtonBase.WndProc (Message&米)在System.Windows.Forms.Button.WndProc (Message&米)在System.Windows.Forms.Control.ControlNativeWindow.OnMessage (Message&米)在System.Windows.Forms.Control.ControlNativeWindow.WndProc (Message&米)在System.Windows.Forms.NativeWindow。DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)在System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW (MSG&味精)System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop (IntPtrdwComponentID, Int32 reason, Int32 pvLoopData)System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (Int32原因,ApplicationContext上下文)System.Windows.Forms.Application.ThreadContext.RunMessageLoop (Int32原因,ApplicationContext上下文)在System.Windows.Forms.Application。运行(mainForm形式)在MD5_Loader.Program.Main() in d:'Dropbox'Bots'World of Warcraft'MD5Loader'MD5 Loader'MD5 Loader'Program.cs:line 19
InnerException:

代码如下:

using System;
using System.Data;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace MD5_Loader
{
    public partial class MainForm : Form
    {
        private const string Server = "xxx.xxx.xxx.xxx";
        private const string Port = "3306";
        private const string Md5DataBase = "database";
        private const string Md5Table= "Builds";
        private const string DbUser = "admin";
        private const string DbPass = "admin";
        private string _fileName = "";
        private string _md5 = "";
        public MainForm()
        {
            InitializeComponent();
        }
        private void btn_Upload_Click(object sender, EventArgs e)
        {
            try
            {
                //Variable for MySQL server Connection
                const string myConString = "Server=" + Server + ";" +
                                           "PORT=" + Port + ";" +
                                           "DATABASE=" + Md5DataBase + ";" +
                                           "Persist Security Info=No;" +
                                           "Encrypt=True;" +
                                           "SslMode=Required;" +
                                           "username=" + DbUser + ";" +
                                           "password=" + DbPass + ";";
                MessageBox.Show(tbx_Revision.Text + Environment.NewLine +
                                CheckMd5(tbx_FileName.Text) + Environment.NewLine +
                                         Path.GetFileNameWithoutExtension(tbx_FileName.Text));
                using (var conn = new MySqlConnection(myConString))
                {
                    using (var cmd = new MySqlCommand(
                        "INSERT INTO " + Md5Table +
                        "(Revision, CheckSum, Product) " +
                        "VALUES (@Revision, @CheckSum, @Product)",
                        conn))
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.Parameters.AddWithValue("@Revision", tbx_Revision.Text);
                        cmd.Parameters.AddWithValue("@CheckSum", CheckMd5(tbx_FileName.Text));
                        cmd.Parameters.AddWithValue("@Product", Path.GetFileNameWithoutExtension(tbx_FileName.Text));
                        conn.Open();
                        try
                        {
                            cmd.ExecuteNonQuery();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                        finally
                        {
                            cmd.Dispose();
                        }
                    }
                    conn.Close();
                    conn.Dispose();
                }
            }
            catch (MySqlException err)
            {
                MessageBox.Show("Error: " + err);
            }
        }
    }
}

未处理的类型为'System.ArgumentException'发生在System.Data.dll中

答案以密码的形式出现。从托管站点生成的密码在密码中包含";"。这导致了连接字符串中的错误。我感谢大家的帮助。有时候,必须对问题进行消毒,才能得出正确的答案。谢谢你的宝贵时间。

在web中添加以下代码。配置

  <appSettings>   
    <add key="ConSecMode" value="OPEN"/>
  </appSettings>