Unable to connect to my mysql database
Hello, I want to connect to MySQL database, but it doesn't want to connect.
I have bought Web Hosting and domain name at Truehoster.
I connected to cPanel and made the following things:
- I created a new database
- I created a user with all privileges
- I went to Remote MySQL and added my IP
I tried to connect with many programs and applications but was unsuccessful.
I have a c# script for testing. The code is here if you need it but it works because I had no problems to connect with my program to one of free MySQL database from freemysqlhosting.
I get this error when I use my database from Truehoster:
System.TimeoutException: 'Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.'
Or in some programs or applications, it is just connecting forever. I'm pretty sure I put the correct database name, username, and password. My C# program:
If this helps when I put some random host, for example, ns111.truehoster.com it gives me this error(2), but if I put incorrect username and or password It doesn't change anything (it shows the first error). Error(2): MySql.Data.MySqlClient.MySqlException: 'Unable to connect to any of the specified MySQL hosts.'
I'm really confused about this problem and don't know what I'm doing wrong. So I would be really grateful for any help.
Or in some programs or applications, it is just connecting forever. I'm pretty sure I put the correct database name, username, and password. My C# program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string serverIp = "ns111.truehoster.net";
string databaseName = "my-database-name";
string username = "user";
string password = "password";
string createTableQuery = string.Format(@"CREATE TABLE `{0}` (
`sid` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(120) NOT NULL DEFAULT '',
`title` varchar(120) NOT NULL DEFAULT '',
`description` text NOT NULL,
`optionscode` text NOT NULL,
`value` text NOT NULL,
`disporder` smallint(5) unsigned NOT NULL DEFAULT '0',
`gid` smallint(5) unsigned NOT NULL DEFAULT '0',
`isdefault` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`sid`),
KEY `gid` (`gid`))
ENGINE = MyISAM AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8;", "TestTable1");
string dbConnectionString = string.Format("server={0};uid={1};pwd={2};database={3};", serverIp, username, password, databaseName);
try
{
MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection(dbConnectionString);
conn.Open();
var cmd = new MySql.Data.MySqlClient.MySqlCommand(createTableQuery, conn);
cmd.ExecuteNonQuery();
Console.WriteLine("done");
}
catch (Exception)
{
Console.WriteLine("nope");
throw;
}
Console.ReadKey();
}
}
}
If this helps when I put some random host, for example, ns111.truehoster.com it gives me this error(2), but if I put incorrect username and or password It doesn't change anything (it shows the first error). Error(2): MySql.Data.MySqlClient.MySqlException: 'Unable to connect to any of the specified MySQL hosts.'
I'm really confused about this problem and don't know what I'm doing wrong. So I would be really grateful for any help.
-
you are going to need to contact your provider Note: most providers block remote mysql connections for obvious security reasons 0 -
Hello, The previous post is correct. This is something you should report to your web hosting provider, as it's possible they have firewall rules blocking external connections to the MySQL service. Thank you. 0
Please sign in to leave a comment.
Comments
2 comments