Error
MySql.Data.MySqlClient.MySqlException
Message=Unable to connect to any of the specified MySQL hosts.
Cant conect to mysql database
From wortbench work normaly
class Constants
{
#region MYSQL CONNECTION STRING
public static string connectionString = "Server=ip_adress;Database=bss_2023;Uid=root;Pwd=password;";
#endregion
#region MYSQL SELECT ALL QUERY
public static string selectAllQuery = "select * from bss_2023.tip";
#endregion
#region MYSQL INSERT COMMAND
public static string insertNote = "insert into tip (id,naziv) values(@id,@naziv);";
#endregion
}
Goran BibicPosted Aug 12, 2023, 7:20 AM
My database work normaly remotly
From any loaction
Don't wotk from app
Visual studio xamarine
All things you write work normaly
Tahir AnsariPosted Aug 11, 2023, 2:05 PM
Troubleshooting MySQL connection issues can involve several steps
1. Connection String: Ensure that you're using the correct connection string in your code. It should include the correct server address, port, username, and password. Make sure that you didn't misspell any part of it.
2. Firewall and Network Configuration: Sometimes, firewalls or network configurations can block the connection from your application. If you can connect from MySQL Workbench, it's possible that your application is being blocked by a firewall. Make sure that your application has the necessary permissions to establish outgoing connections.
3. MySQL Server Configuration : Check the MySQL server's configuration to ensure that it's set up to accept remote connections. The `bind-address` in the MySQL configuration file (`my.cnf` or `my.ini`) should be set to the appropriate IP address (or `0.0.0.0` to listen on all available network interfaces) if you want to allow remote connections.
4. MySQL User Permissions: Make sure that the MySQL user you're using in your application has the proper permissions to connect from the host where your application is running. You might need to grant permissions using a command like:
5. MySQL Server Status : Ensure that the MySQL server is running. You can check the server's status through the command line or by attempting to connect with a client like MySQL Workbench.
6. Port Number : Double-check the port number in your connection string. MySQL typically uses port 3306 by default, but if your server is configured differently, make sure the port matches.
7. Connection Timeout : If your application is using a very short connection timeout, it might not give enough time for the connection to establish, especially if there's a delay in network communication. Try increasing the connection timeout in your connection string.
8. Proxy Settings If your application runs behind a proxy, make sure that proxy settings are correctly configured for MySQL connections.
9. Antivirus or Security Software : Sometimes, security software can interfere with outgoing connections. Temporarily disabling your security software (if safe to do so) can help diagnose if it's causing the issue.
10. Driver Compatibility : Ensure that you're using the correct version of the MySQL .NET Connector (driver) that is compatible with your MySQL server version.
11. Exception Handling : Wrap your database connection code in proper exception handling to catch and display any specific error messages that might help diagnose the issue more accurately.