0

スマートデバイスプロジェクトは初めてです。MySQL ConnectorNet6.4.4をインストールしました。そして、2008年のmysql接続用にMySql.Data.CFを追加します。

しかし、出力を取得できません。指定されたMySQLホストのいずれにも接続できません。」connection.open()での例外。

server=192.168.1.100;User Id=mcubic;Persist Security Info=True;database=mcubic

その有効な接続文字列。したがって、データベースサーバーのユーザーID、パスワードは正しいです。その問題はありません。しかし、スマートデバイスプロジェクトだけでエラーが発生した理由がわかりません。

以下のコード。

try
 {
    string connectionString = "server=192.168.1.100;User Id=mcubic;Persist Security Info=True;database=mcubic";
    string query = "select b.Outlet_Master_Name from mcs_user_outlet a,outlet_master b where a.Mcs_User_Outlet_User_Id=3 and a.Mcs_User_Outlet_Outlet_Id = b.Outlet_Master_Id";
    MySqlConnection connection = new MySqlConnection(connectionString);
    MySqlCommand command = new MySqlCommand(query, connection);
    connection.Open();
    MySqlDataReader Reader = command.ExecuteReader();
    while (Reader.Read())
    {
        comboBox1.Items.Add(Reader[0].ToString());
    }
    connection.Close();
 }
catch(Exception ex)
{
     MessageBox.Show(""+ex.Message);
}

エラーを見つけるのを手伝ってください。

以下の接続文字列を試しました。

server=192.168.1.100;UID=mcubic;Persist Security Info=True;database=mcubic

server=192.168.1.100;User Id=mcubic;Persist Security Info=False;database=mcubic

server=192.168.1.100;User Id=mcubic;Persist Security Info=False;Initial Catalog=mcubic;

server=192.168.1.100;UID=mcubic;Persist Security Info=True;database=mcubic;pooling = false;

しかし、役に立たない。

4

2 に答える 2

2

私は私の問題を解決します。これがあなたにも役立つことを願っています。以下のコードは私にとって完璧に機能しています。

    DataSet ds = new DataSet();
    MySqlConnection conn = new MySqlConnection("server=server-ip;database=db-name;Character Set=utf8;Uid=user-name;password=****;");
    MySqlCommand cmd = new MySqlCommand("select * from table-name", conn);
    MySqlDataAdapter da = new MySqlDataAdapter();
    conn.Open();
    da.SelectCommand = cmd;
    da.Fill(ds);
    dataGridView1.DataSource = ds.Tables[0];
    conn.Dispose();
    cmd.Dispose();
于 2012-01-25T15:16:26.223 に答える
0

あなたの問題は、スマート デバイスが外部ネットワークに接続する方法が原因である可能性があると思います。エミュレーターを使用して Visual Studio からこれを実行しようとしていると思います。

サーバー自体に接続する前に、MySql サーバーが存在する外部ネットワークに接続する必要があると思います。

あなたの問題をカバーする記事がここにありますが、SQL Serverに関するものです。あなたが経験しているのと同じ問題をカバーすると確信しています。

于 2012-01-24T08:21:45.860 に答える