简体   繁体   English

如何使用我的C#应用​​程序连接到远程MySQL Server

[英]How to Connect to Remote MySQL Server with my C# Application

I need to connect my C# application developed in my Standalone PC with my Hosted Linuux MySQL Server. 我需要将在独立PC中开发的C#应用​​程序与Hosted Linuux MySQL Server连接起来。 How can i do it.. Is there any server configuration setup or any kind of Remote Connection Permission Setting have to be done? 我该怎么办。是否必须进行任何服务器配置设置或任何类型的远程连接权限设置? Please help with this.. 请对此提供帮助。

Make sure that the server where MySQL is at can accept connections. 确保MySQL所在的服务器可以接受连接。

Read this to read how to configure your c# application to connect to MySQL. 阅读本文以了解如何配置c#应用程序以连接到MySQL。

The connection string code should like this 连接字符串代码应如下所示

Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

You need to allow the remote connection by this way 您需要通过这种方式允许远程连接

Mysql has very good documentation how to connect mysql server (local and remote). Mysql有很好的文档,介绍如何连接mysql服务器(本地和远程)。 It is here http://dev.mysql.com/doc/index-connectors.html And your case may be this http://dev.mysql.com/doc/connector-c/en/index.html 它在这里http://dev.mysql.com/doc/index-connectors.html,而您的情况可能是http://dev.mysql.com/doc/connector-c/en/index.html

Its Pretty Simple to Implement 1) Download My Sql Connector From https://dev.mysql.com/downloads/connector/net/6.9.html 实施起来非常简单1)从https://dev.mysql.com/downloads/connector/net/6.9.html下载My Sql Connector

2) In your C# Project add refrence of Mysql.Data.Dll 2)在您的C#项目中添加Mysql.Data.Dll的引用

3) use this Connection String string connectionString= "SERVER=000.000.000.000;DATABASE=testdb;UID=test;PASSWORD=test123;" 3)使用此连接字符串字符串connectionString =“ SERVER = 000.000.000.000; DATABASE = testdb; UID = test; PASSWORD = test123;” 4) use same like this sample code 4)使用像这样的示例代码

MySqlConnection conn = new MySqlConnection(connectionString);
        try
        {
            Console.WriteLine("Connecting to MySQL...");
            conn.Open();
            // Perform database operations
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
        conn.Close();
        Console.WriteLine("Done.");

or Read this tutorials https://dev.mysql.com/doc/connector-net/en/connector-net-tutorials-connection.html 或阅读本教程https://dev.mysql.com/doc/connector-net/en/connector-net-tutorials-connection.html

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

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