Hello friends
I am trying to connect to my MySql database on a dedicated server (from my home computer), but i keep running into different kind of errors. I keep debugging and try to solve the problems, but the last error is kinda driving me crazy, so I hope you can help me with my problem.
- I have installed MySQL Connector .Net 5.2.1
- I have installed MySQL Connector ODBC
- I have created a new Project in VWD 2008 Express and included the MySql.Data.dll into my Bin folder
- And I use the following code to connect to my MySql database:
Web.config:
<connectionStrings>
<add name="myConStr" connectionString="server=serverIP; database=dbName; user id=uName; password=pName;"/>
</connectionStrings>
MasterPage.master.cs
using MySql.Data.MySqlClient;
....
try
{
using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["myConStr"].ConnectionString.ToString()))
{
con.Open();
using(MySqlCommand cmd = new MySqlCommand("SELECT [field1] FROM [table] WHERE [field2] <= 10", con))
using(MySqlDataReader dr = cmd.ExecuteReader())
{
ddlUsers.DataSource = dr;
ddlUsers.DataBind();
dr.Close();
}
con.Close();
}
}
catch(Exception ex)
{
errorMsgTop.Text = ex.Message.ToString();
}
dllUsers is an <asp:DropDownList>.
But I keep getting this error:
error msg: Unable to connect to any of the specified MySQL hosts.
error source: MySql.Data
It's complaining about con.open(). I've tryed to connect with these database login values with my other (classic ASP) projekt and it works fine, but I can't make it work with ASP.NET. Can you please help me with this problem?