provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接
代码如下:usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;u...
代码如下:using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void getData()
{
SqlConnection cn = new SqlConnection("server=localhost;database=Northwind;user=da;password=da");
SqlCommand cmd = new SqlCommand("select * form Customers", cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Customers");//在这里出现问题
this.GridView2.DataSource = ds.Tables[0].DefaultView;
this.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
getData();
}
} 展开
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void getData()
{
SqlConnection cn = new SqlConnection("server=localhost;database=Northwind;user=da;password=da");
SqlCommand cmd = new SqlCommand("select * form Customers", cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Customers");//在这里出现问题
this.GridView2.DataSource = ds.Tables[0].DefaultView;
this.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
getData();
}
} 展开
展开全部
Sql Server->配置工具->sql server外围应用配置器->服务和连接的外围应用配置器->打开MSSQLSERVER节点下的Database Engine 节点,先择"远程连接",接下建议选择"同时使用TCP/IP和named pipes",确定后,重启数据库服务就可以了.
如果还出现错误的话 那么请你检查一下所写的代码connectionString中的Data Source这个属性填写的值是否正确 本机默认填写.\SQLEXPRESS 或者换成 计算机名\SQLEXPRESS ...
如果还出现错误的话 那么请你检查一下所写的代码connectionString中的Data Source这个属性填写的值是否正确 本机默认填写.\SQLEXPRESS 或者换成 计算机名\SQLEXPRESS ...
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询