简体   繁体   English

通过C#/ Visual Studio 2012连接到外部mysql数据库

[英]Connecting to external mysql database through C#/Visual Studio 2012

Whenever I try to perform a SQL query with an insert on my localhost, it works, using simple C# code with the Mysql.Data reference in visual studio. 每当我尝试使用我的localhost上的插入执行SQL查询时,它就可以使用简单的C#代码和visual studio中的Mysql.Data引用。 But when I try to connect to my own database I have on a webserver, it gives me an exception: 但是当我尝试连接到我自己的数据库时,我在网络服务器上,它给了我一个例外:

A first chance exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. MySql.Data.dll MySql.Data.MySqlClient.MySqlException(0x80004005)中发生了'MySql.Data.MySqlClient.MySqlException'类型的第一次机会异常:无法连接到任何指定的MySQL主机。

Is my webserver bocking external requests from visual studio / c#? 我的网络服务器是否存在来自visual studio / c#的外部请求? How do I open the server to allow these requests? 如何打开服务器以允许这些请求?

Thank you. 谢谢。

I had developed one application in c# in that I had used MySQL database as back end that stored at bigrock.com. 我在c#中开发了一个应用程序,因为我使用MySQL数据库作为存储在bigrock.com的后端。 In your application their will be simple mistake in connection string. 在您的应用程序中,连接字符串中的简单错误。 And turn off your firewall and your antivirus settings to off. 并关闭防火墙和防病毒设置。

This is the right format of MySQL database connection string :- 这是MySQL数据库连接字符串的正确格式: -

string connectionString = "Server=Your_Server_Name;Uid=Your_User_Name;Database=Your_Database_Name;port=Your_Port_No;Pwd=Your_Password;Allow Zero Datetime=true";

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

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