我是.NET的新手,在这方面,我正在开发Windows窗体应用程序。我试图将我的应用程序连接到Visual Studio服务数据库。我只是在提交按钮后面编写了一段代码。
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\\Users\\mudasir\\Documents\\Visual Studio 2012\\Projects\\Medical_Store_System\\Medical_Store_System\\MSS_database.mdf;Integrated Security=True");
con.Open();
if (con.State == ConnectionState.Open)
{
textBox1.Text = "Congrats";
}
else
textBox1.Text = "Sorry";
con.Close();
}
在con.open();时,我遇到了一个异常,显示如下:
"在建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。未找到服务器或无法访问。请验证实例名称是否正确,并且 SQL Server 已配置为允许远程连接。 (提供程序: Named Pipes Provider,错误: 40 - 无法打开到 SQL Server 的连接)"
请给我一个简单的答案和解决方案,因为我对这些东西很新。