I am using default port (3306) of mySQL
and my connecting string is like
Server=184.27.45.87;Database=xxxxx;Uid=xxxxx;Pwd=yyyyy
Still I am getting error at line
con.Open()
getting exception
MySqlException: Unable to Connect to any of specified MySQL hosts
stack trace
A first chance exception of type 'System.Threading.ThreadAbortException' oc7curred in mscorlib.dll
An exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll but was not handled in user code
The thread 0x1944 has exited with code 0 (0x0).
A first chance exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.DLL
Note that you should use uid
instead of User ID
of the SQL query string is as follows:
server=$servername$;database=$databasename$;uid=$username$;password=$password$;
Where $servername$
is the name of the machine where your MySQL Server is running (localhost if it's on your own machine) and $databasename$
the name of your database (or catalog, as some call it), $username$
a user which is allowed to access the database you selected and $password$
the password of the user.
Example:
//create a MySQL connection with a query string
MySqlConnection connection = new MySqlConnection("server=localhost;database=cs;uid=root;password=abcdaaa");
//open the connection
connection.Open();
//close the connection
connection.Close();
I had a similar issue. My MySQL server was on a remote machine and by default it does not accept remote connections. I had to explictly add my machine's IP address to its list of accepted IPs.
I had the similar issue when MySqlConnector trying to connecting using IPV6. Same error. You need to update your driver.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.