SQL 服务器:命名管道错误

SQL Server: Named Pipes error

我在 VM 上安装了 Visual Studio 2015 和 SQL Server Express。

单击 Visual Studio 上的 运行 按钮时出现以下错误:

An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

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)

页面中的代码:

protected void Page_Load(object sender, EventArgs e) { 
SqlConnection con = new SqlConnection("data source=.; database = Sample2; integrated security=SSPI"); 
SqlCommand cmd = new SqlCommand("Select * from tblemployee", con); con.Open(); 
SqlDataReader rdr = cmd.ExecuteReader(); 
GridView1.DataSource = rdr; 
GridView1.DataBind(); 
con.Close(); 

默认,SQL服务器Express安装为命名实例 称为 SQLEXPRESS。因此,除非您在安装期间特别更改了任何内容,否则您应该能够使用此连接字符串连接到它:

data source=.\SQLEXPRESS;database=Sample2;integrated security=SSPI"