简体   繁体   English

无法从C#Windows应用程序连接到MySQL

[英]Can't connect to MySQL from C# windows application

I implement an C# windows application and I always connected to sql server for testing. 我实现了C#Windows应用程序,并且始终连接到sql server进行测试。 Now I would like to connect it to the MySQL on hosting server to link some booking data from my website. 现在,我想将其连接到托管服务器上的MySQL,以链接我网站上的一些预订数据。 I use the same address and port that shows on the url when I connect to the phpMyAdmin. 当我连接到phpMyAdmin时,使用与URL中显示的地址和端口相同的地址。 And this is my configuration in my application. 这是我在应用程序中的配置。

private string connectionStr = "SERVER=203.78.yyy.xx;PORT=2082;DATABASE=db_name;UID=user;PASSWORD=password;";

But I always receive the timeout exception and I don't know what is the problem exactly. 但是我总是收到超时异常,我不知道到底是什么问题。 I also tried to connect with phpMyAdmin on my localhost and it works fine. 我还尝试在本地主机上与phpMyAdmin连接,并且工作正常。

Any ideas? 有任何想法吗?

To be able to connect using Server Explorer I had to install an ADO.NET driver MySQL .NET Connector 为了能够使用Server Explorer进行连接,我必须安装ADO.NET驱动程序MySQL .NET Connector

To connect via code, I was adding a reference to MySql.Data.dll and connection string such as 为了通过代码进行连接,我添加了对MySql.Data.dll和连接字符串(例如)的引用

"Server=myServerAddress;Port=1234;Database=myDataBase;Uid=myUsername;Pwd=myPassword;" “服务器= myServerAddress;端口= 1234;数据库= myDataBase; Uid = myUsername; Pwd = myPassword;”

And I was getting the timeout too, but only when the data was rather big. 我也得到了超时,但是只有当数据量很大时。 The problem was with TCP/IP ports and the solution I found is in here , also checkout this blog 问题出在TCP / IP端口,我找到的解决方案在这里 ,也请查看博客

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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