2016-05-01 16 views
0

localhostを使用してアプリケーションをmysqlサーバに接続しようとしています。私が直面している問題は、私の理解を超えています。私はそれを検索しようとしましたが、解決策を見つけることができませんでした。キーワードがconnectionStringでサポートされていません

を "キーワードはサポートされていません: 'UID'" を示す

エラー。以下は

コードです:

のForm1.cs

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using System.Data.SqlClient; 
using System.Data.Sql; 
using System.Data.CData.MySQL; 
using MySql.Data.MySqlClient; 



namespace DataAccess 
{ 
    public partial class Form1 : Form 
    { 

     public Form1() 
     { 

      InitializeComponent(); 
     } 

     private void label4_Click(object sender, EventArgs e) 
     { 

     } 

     private void button1_Click(object sender, EventArgs e) 
     { 

      MySQLConnection connection; 

      String server = "localhost", database = "Student", userid = "root", password = "12345"; 
      String connectionString = "SERVER = " + server + ";" + "DATABASE = " + database + ";" + "USERID =" + userid + ";" + "PASSWORD = " + password + ";"; 

      String std_name = textBox1.Text, std_program = comboBox1.Text, std_department = comboBox2.Text; 
      int std_age = Convert.ToInt32(textBox2.Text); 
     // MySQLDataAdapter mda = new MySQLDataAdapter("Insert into student.registration(Name, Age, Program, Department) Values(@std_name,@std_age,@std_program,@std_department)", connection); 
      connection = new MySQLConnection(connectionString); 
      MySQLCommand cmd; 
      connection.Open(); 

      try 
      { 
       cmd = connection.CreateCommand(); 
       cmd.CommandText = "Insert into Student(Name, Age, Program, Department) Values(@std_name,@std_age,@std_program,@std_department)"; 
       cmd.ExecuteNonQuery(); 
       MessageBox.Show("Record Successfully Entered!"); 
      } 
      catch (Exception) 
      { 
       throw; 
      } 
      finally 
      { 
       if (connection.State == ConnectionState.Open) 
       { 
        connection.Close(); 

       } 
      } 
     } 
    } 
} 
+0

エラーは何ですか? rootユーザーに適切なアクセスを許可しましたか? http://stackoverflow.com/questions/8484722/access-denied-for-user-rootlocalhost-while-attempting-to-grant-privilegesを参照してください。 –

答えて

1

ここにあなたの接続文字列をチェックし

https://www.connectionstrings.com/mysql/

標準的な方法は、

Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; 
です

いくつかのキーはあなたと違っています...

+0

自分のコードを変更しましたが、同じエラーが表示されます。 – Mikka

+0

あなたのmysqlが動作しているかどうかを確認し、ポート3306でlocalhostを聞いてください –

+0

それはポート80で実行されています。 – Mikka

関連する問題