c#Mysql Connect:字典中没有给定的密钥

时间:2016-11-15 14:47:15

标签: c# mysql dictionary

我的新c#项目出了问题。有以下例外:The given key was not present in the dictionary。我有一个数据库和一个空数据表。 我写了以下代码:

using System.Data.MySqlClient;
namespace ConnectingToMySqlDB
{
    public partial class Form1 : Form
    {
        MySqlConnection conn;
        string connString;

        public Form1()
        {
            InizialiteComponent();
        }

        private void bntSendData_Click(object sender, EventArgs e)
        {
            connString = "SERVER=db4free.net;PORT=3306;DATABASE=namedb;UID=username;PWD=pass;";
            try
            {
                conn = new MySqlConnection();
                conn.ConnectionString = connString;
                conn.Open();
                MessageBox.Show("Connected");
                conn.Close();
            }
            catch(Exception ex)
            { MessageBox.Show(ex.Message); }
        }
    }
}

哪里出错了?为什么它不起作用?

0 个答案:

没有答案