当我尝试将插入值连接到数据库时,我遇到了标题中的错误。我的调试错误出现在:
使用(var conn = new MySqlConnection(myConString))
以下是VS2013的错误:
System.ArgumentException未处理HResult = -2147024809
Message =初始化字符串的格式不符合 规范从索引153开始.Source = System.Data
堆栈跟踪: 在System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString,Int32 currentPosition,StringBuilder buffer,Boolean useOdbcRules,String& keyname,String&核心价值) 在System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable,String connectionString,Boolean buildChain,Hashtable 同义词,布尔firstKey) 在System.Data.Common.DbConnectionOptions..ctor(String connectionString,Hashtable synonyms,Boolean useOdbcRules) 在System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String 值) at MySql.Data.MySqlClient.MySqlConnectionStringBuilder..ctor(String connStr) at MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString(String 值) at MySql.Data.MySqlClient.MySqlConnection..ctor(String connectionString) 在d:\ xxxx \ MD5中的MD5_Loader.MainForm.btn_Upload_Click(Object sender,EventArgs e) Loader \ 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(消息& m,MouseButtons按钮,Int32点击) 在System.Windows.Forms.Control.WndProc(消息& m) 在System.Windows.Forms.ButtonBase.WndProc(消息& m) 在System.Windows.Forms.Button.WndProc(消息& m) 在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam) 在System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 在System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr) dwComponentID,Int32原因,Int32 pvLoopData) 在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32) 原因,ApplicationContext上下文) 在System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32) 原因,ApplicationContext上下文) 在System.Windows.Forms.Application.Run(Form mainForm) 在MD:_Loader.Program.Main()的d:\ Dropbox \ Bots \ World of Warcraft \ MD5Loader \ MD5 Loader \ MD5 Loader \ Program.cs:第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);
}
}
}
}
答案 0 :(得分:0)
答案以密码的形式出现。来自托管站点的生成密码包含“;”在密码中。这导致连接字符串中的错误。我感谢大家的帮助。有时必须清理问题会禁止正确的答案。我很感激你的时间。
答案 1 :(得分:-2)
在web.config中添加以下代码
<appSettings>
<add key="ConSecMode" value="OPEN"/>
</appSettings>