2014-07-07 3 views
0

쉬운 문제이지만 오류를 찾을 수 없습니다. 내 데이터베이스에 데이터를 저장하고 싶습니다. 그때 나는 Visual Studio에서 내 응용 프로그램에서 내가 만드는 마이크로 소프트 SQL Server 2008에 "Examen"라는 이름의 데이터베이스를 생성이 같은 연결 문자열 :지정한 MySQL 호스트에 연결할 수 없습니다.

다음
string connectionstring = @"Data Source=.\sqlexpress;Initial Catalog=Examen;Integrated Security=True"; 

나는 "테스트"테이블에 데이터를 삽입하기 위해이 코드를 사용 : 이 코드를 실행하는 경우 당신은 MySQLMSSQL을 혼합하는 연결을

Unable to connect to any of the specified MySQL hosts. 
+0

MySQL과 SQLServer에 두 개의 서로 다른 짐승이 숙지해야 –

답변

1

할 때도

MySqlConnection connection = new MySqlConnection(connectionstring); 
MySqlCommand cmd; 
connection.Open(); 

try 
{ 
    cmd = connection.CreateCommand(); 
    cmd.CommandText = "Insert into Examen.Test (nom,prenom) values (" + txbnom.Text + "," + txbprenom.Text + ") "; 
    cmd.ExecuteNonQuery(); 
    MessageBox.Show("ok"); 
} 
catch (Exception) 
{ 
    throw; 
} 
finally 
{ 
    if(connection.State == ConnectionState.Open) 
    { 
    connection.Close(); 
    } 
} 

내가 오류가 있었다.

정말 MySQL 서버에 연결 하시겠습니까? MSSQL에 연결하려면 http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection(v=vs.110).aspx을 사용하십시오.

또한 당신은 SQL injection

관련 문제