简体   繁体   中英

Connecting to a remote MySQL database

I am trying to create a connection between my test WPF application and a MySql (phpmyadmin) database. Right now, I tried every suggestions from other topics with similar problems, none worked.

I have an user with all privileges( http://prntscr.com/ehhrdv ) and one dummy table.

My connection code looks like this:

string conectionString = "Server = r310.reseller.si; Database = ******; Uid = ******; Pwd = ******";



         myConnection = new MySqlConnection(conectionString);

        try { myConnection.Open(); } catch(MySqlException ex)
        {
            MessageBox.Show(ex.ToString());
        }

The error I'm getting:

 MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at WpfApplication2.MainWindow.pressMe_Click(Object sender, RoutedEventArgs e) in C:\Users\Tomi\Documents\Visual Studio 2015\Projects\WpfApplication2\WpfApplication2\MainWindow.xaml.cs:line 51

I am not sure wether my user has no privileges for a remote connection or something else.

I am managing the database from my job's reseller website.

Try adding:

Driver={SQL Server Native Client 11.0};

at the beginning of the connection string, ie:

string conectionString = "Driver={SQL Server Native Client 11.0};Server=r310.reseller.si;Database=******;Uid=******;Pwd=******";

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM