简体   繁体   English

C#连接到mysql服务器

[英]C# connect to mysql server

I need your help on this one. 我需要你的帮助。

I got the error message which is stated: 我收到了错误消息:

"network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)". “在建立与SQL Server的连接时发生与网络相关或特定于实例的错误。未找到服务器或无法访问服务器。验证实例名称是否正确以及SQL Server是否配置为允许远程连接。(提供者:已命名)管道提供程序,错误:40 - 无法打开与SQL Server的连接)“。

I was trying to connect other local computer local host using ip. 我试图使用ip连接其他本地计算机本地主机。 My code: 我的代码:

    public DbStudent()
    {
        UGIcon = new SqlConnection();
        UGIcon.ConnectionString = "server= IPAddress;user="id";password="pass";database=MyDB";
    }
    public SqlConnection Open()
    {
        UGIcon.Open();
        return UGIcon;
    }

    public void Close()
    {
        UGIcon.Close();
    }

Could somebody help me out please? 有人可以帮帮我吗?

You need to download the installation from MySql 您需要从MySql下载安装

There you'll get a driver for the mysql-database 在那里你将获得mysql数据库的驱动程序

The SqlConnection is used to access SQL Server, for another database use OleDbConnection . SqlConnection用于访问SQL Server,另一个数据库使用OleDbConnection So, if you want connect to MySQL use OleDbConnection instead. 所以,如果你想连接MySQL改用OleDbConnection

    public DbStudent()
    {
        UGIcon = new OleDbConnection();
        UGIcon.ConnectionString = "Server=IPAddress;Database=MyDB;Uid=id;Pwd=pass;";
    }

You can see here for MySQL Connection String 你可以在这里看到MySQL连接字符串

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

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