我試圖連接到一個免費的在線數據庫(db4free.net),我不能在程序試圖打開連接時拋出KeyNotFoundException。KeyNotFoundException與在線數據庫
這裏是我的代碼:
public static class BaseDeDatos {
static string myConnectionString = "SERVER=db4free.net;" + "DATABASE=******;" + "UID=******;" + "PASSWORD=*****;";
static MySqlConnection cnx = new MySqlConnection(myConnectionString);
static String error;
public static int Conectar()
{
int resultado = -1;
try
{
cnx.Open(); //The exception is thrown HERE
if (cnx.State == ConnectionState.Open)
resultado = 1;
}
catch (MySqlException ex)
{
error = ex.Message;
}
return resultado;
}
.
.
.
.
public static void myMethod(){
Conectar();
}
}
當我打電話myMethod()
拋出異常。我可以將此數據庫與MySQLWorkbench連接,並連接到PHP Android,但爲什麼我無法在Visual Studio中使用C#執行此連接?我敢肯定,我做錯了什麼幫助我,請
PD:我讀的是我需要更改我的數據庫的字符集,但它不起作用。我想所有的字符集可獲取
什麼是確切的錯誤信息?你安裝了[Connector/Net](http://dev.mysql.com/downloads/connector/net/)嗎? –
是的,錯誤來自連接字符串,因爲我使用這個連接字符串到其他數據庫,它適用於我,但我認爲,db4free有一個differente連接字符串 – cnbandicoot