2012-01-23 4 views
0

저는 스마트 장치 프로젝트를 처음 사용합니다. 나는 MySQL Connector Net 6.4.4를 설치했다. 그리고 MySql.Data.CF를 mysql 연결에 대해 2008 년 대 추가합니다."지정된 MySQL 호스트에 연결할 수 없습니다." 스마트 장치 프로젝트 VS2008

하지만 출력을 얻을 수 없습니다. "지정된 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; 

하지만 사용하지 마십시오.

+1

관리자 권한으로 Visual Studio를 실행 해 보셨습니까? – ChrisBD

+0

선생님, 그게 무엇입니까? 지금 나는 그것을 시도한다. 하지만 같은 오류가 반복됩니다. – Sagotharan

+1

연결 문자열에서 암호 필드가 누락되지 않았습니까? – ChrisBD

답변

0

스마트 장치가 외부 네트워크에 연결하는 방식 때문일 수 있습니다. 에뮬레이터를 사용하여 Visual Studio에서이 프로그램을 실행하려고합니다.

서버 자체에 연결을 시도하기 전에 MySql 서버가 상주하는 외부 네트워크에 연결해야한다는 점을 알고 있습니다.

article here에는 문제가 있지만 SQL Server가 있습니다. 나는 그것이 당신이 겪고있는 것과 동일한 문제를 다룰 것이라고 확신합니다.

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(); 
+1

오 세상에. 당신은 다양합니다. 감사.나는이 시간을 내줄 것이다. – Sagotharan

관련 문제