Evan Evan - 2 months ago 6
MySQL Question

Unable to connect to Mysql database on a hosted machine

I am using a C# Windows Forms project to use the database on a GoDaddy web host.

This is the error I am getting:

SqlConnection sqlConn = new SqlConnection("Data Source=tibia.db.XXXXX.hostedresource.com; Initial Catalog=tibia; User ID=tibia; Password='XXXXX';");

When I click the button and debug it, it stops here:

SqlCommand sqlComm = new SqlCommand("INSERT INTO player (date, name, level, experience) " +
"VALUES ('" + DateTime.Now.ToString() + "','" +
getPlayerName(Tibia.Handle, (BattleList_Start + Base + (BattleList_Step * playerIndex) + 4)) + "','" +
Convert.ToString(ReadInt32(LvlAdr + Base, 4, Tibia.Handle)) + "','" +
Convert.ToString(ReadInt32(XpAdr + Base, 4, Tibia.Handle)) + ")", sqlConn);

Here is the database information provided by GoDaddy.

All information between the facts and the source are exactly identical and correct.

Does anyone know what I am doing incorrectly?


Your problem is that you are using MSSQL (Microsoft) classes to access a MySQL database. Of course you are getting an error.

You need to use the MySql C# Connector. The syntax should be nearly identical. See this codeproject article for some help setting it up. But the short version is: put MySql before all your "SQL-related" classes and it should work.