命名管道错误40,通过visual studio连接到Xampp


Named pipes error 40, connecting to Xampp through visual studio

我已经设置了Xampp作为服务器来托管我的数据库。

我试图连接到数据库,过滤结果,并输出到基于文本的datagridview在txtSearch

 private void btnTest_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=epas;Persist Security Info=True;uID=root;Password=Password");
        con.Open();
        SqlDataAdapter ada = new SqlDataAdapter("SELECT ID, Description, Retail FROM pricing where ID like'" + txtSearch.Text + "%'", con);
        DataTable dt = new DataTable();
        ada.Fill(dt);
        dataGridView1.DataSource = dt;
        con.Close();
    }
}

但是每次我运行它,我得到相同的错误

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: 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)

如果我输入错误的详细信息,我无法访问,但我已经多次更改连接字符串,无法连接

我正在使用更新的Xampp和visual studio 2013

好了,愚蠢的问题时间到了,xamp是apache, mysql, php和perl。所以你试图连接到一个mysql数据库。如果是这样,你正在使用错误的数据适配器,你正在使用一个mssql数据适配器,你会想要mysql的一个例如https://dev.mysql.com/downloads/connector/net/6.8.html

如果您正在连接到一个mssql数据库,例如其中一个express版本,请忽略。