连接到远程MySQL数据库
问题描述:
我想在我的测试WPF应用程序和MySql(phpmyadmin)数据库之间创建连接。 现在,我尝试了其他类似问题的建议,但都没有成功。连接到远程MySQL数据库
我有一个拥有所有权限的用户(http://prntscr.com/ehhrdv)和一个虚拟表。
我的连接代码如下所示:
string conectionString = "Server = r310.reseller.si; Database = ******; Uid = ******; Pwd = ******";
myConnection = new MySqlConnection(conectionString);
try { myConnection.Open(); } catch(MySqlException ex)
{
MessageBox.Show(ex.ToString());
}
我得到的错误:
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
我不知道我阉用户有一个远程连接或别的东西没有特权。
我从我的工作经销商网站管理数据库。
答
尝试添加:
Driver = {SQL Server Native Client 11.0};
在连接字符串的开头,即:
串conectionString =“驱动程序= {SQL Server本机客户端11.0};服务器= r310.reseller.si;数据库= ******; UID = ******; PWD = ******“;
有一个错误,说不支持关键字。 – someone123321
你检查过你的防火墙吗?可能是防火墙问题 – Lee
我应该特别检查什么? – someone123321