从c#到msql的连接字符串

问题描述 投票:0回答:1

我是msql的新手,正在使用MySQL Workbench 8.0 CE我正在尝试将数据库中的数据绑定到datagridview,如下所示,但下面出现错误

但是我能够使用MySQL Workbench 8.0 CE连接我的数据库,因此连接建立起来,所以我能做什么?

    public void GetPersonData()
    {
        string connstr = "Server=localhost;Database=newsequesterdb;Uid=reser;Pwd=00";
        string query = "SELECT * FROM NEWSEQUESTERDB.PERSON;";

        using (SqlConnection conn = new SqlConnection(connstr))
        {
            using (SqlDataAdapter adapter = new SqlDataAdapter(query, conn))
            {
                DataSet ds = new DataSet();
                adapter.Fill(ds);
                dgv_data.DataSource = ds.Tables[0];
            }
        }
    }

错误消息

System.Data.SqlClient.SqlException: A 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)
c# mysql asp.net-3.5
1个回答
0
投票

SqlConnection特定于MS SQL Server。请改用MySqlConnection(以及相关的命令和数据适配器类)。

© www.soinside.com 2019 - 2024. All rights reserved.