简体   繁体   English

用C#连接mysql

[英]connect mysql with c#

I'm building ac# windows application which will connect with the mysql database in a remote server. 我正在构建ac#Windows应用程序,它将与远程服务器中的mysql数据库连接。

I'm using the following connect script 我正在使用以下连接脚本

string connectionString;
connectionString = "SERVER = eu5.org;UID = myuserid; PASSWORD = mypassword; DATABASE = mydatabasename;";
connection = new MySqlConnection(connectionString);

It shows the error couldn't connect to the database. 它显示错误无法连接到数据库。

PS: Mysql database is at eu5.org server PS:Mysql数据库位于eu5.org服务器上

Personally I prefer to use the MySql Workbench IDE for testing connections and working (Querying) the database directly where possible. 我个人更喜欢使用MySql Workbench IDE来测试连接并在可能的情况下直接工作(查询)数据库。 Most hosted databases that I have worked with normally define the Server as Instance.[DomainName] so I would have expected your server URL to be something like MySql1.eu5.org 我使用过的大多数托管数据库通常都将服务器定义为实例。[DomainName],因此我希望您的服务器URL类似于MySql1.eu5.org。

Below is a connection string that I tested using the MySql Connector , change the parameters. 以下是我使用MySql Connector测试的连接字符串,请更改参数。

<connectionStrings>
    <add name="MySqlConnection" connectionString="server=INSTANCENAME.DOMAINNAME.COM;UID=USERNAME;password=PASSWORD;database=DATABASENAME;Persist Security Info=True;" providerName="MySql.Data.MySqlClient"/>

确保应该启动服务器...

Your code is correct. 您的代码是正确的。 Use a browser for MySQL, like http://mysql-query-browser-for-windows.apponic.com/ to check if your database is available. 使用适用于MySQL的浏览器(例如http://mysql-query-browser-for-windows.apponic.com/)检查数据库是否可用。

Just read the FAQ: 只需阅读常见问题解答:

Many people want to only use database, but their site is hosted elsewhere. 许多人只想使用数据库,但是他们的站点托管在其他地方。 We provide free database for websites hosted with us. 我们为托管网站提供免费数据库。 For that reason, external access is blocked without exception. 因此,外部访问无一例外地被阻止。

--> http://www.freewebhostingarea.com/faq.html -> http://www.freewebhostingarea.com/faq.html

so it's not possible to access your MySQL-DB from external sources. 因此不可能从外部源访问MySQL-DB。 only localhost will be allowed 只允许本地主机

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

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