我已经将Xampp设置为服务器来承载我的数据库。
我试图连接到数据库,过滤结果,并根据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
发布于 2015-06-03 23:36:27
好的愚蠢的问题时间,xamp是apache,mysql,php和perl。那么,您是否试图连接到mysql数据库。如果是这样的话,您使用的是错误的数据适配器,您使用的是mssql数据适配器,您将需要mysql的数据适配器,例如https://dev.mysql.com/downloads/connector/net/6.8.html。
如果您正在连接到mssql数据库,例如其中一个特快专递版本,请忽略。
https://stackoverflow.com/questions/30320071
复制相似问题