我下面这段代码,为什么编译的时候会出错?我的电脑上是安装了SQL2000和2005的,但是调试的时候总是卡在红色的代码上,报错为“异常详细信息: System.Data.SqlClient.SqlException: 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接)"可我是在2000上建立的数据库啊,帮忙看看应该怎么修改一下。public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable ds = getData();
string m = ds.Rows[0]["U_name"].ToString();
Label1.Text = m;
}
private DataTable getData() //构造getData()
{
SqlConnection con = new SqlConnection("data source=(localhost);database=OA;user id=sa;password=sa123");
SqlDataAdapter sa = new SqlDataAdapter("select top 1 * from T_UserInfo", con);
DataSet ds = new DataSet();
sa.Fill(ds);
return ds.Tables[0];
}}
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable ds = getData();
string m = ds.Rows[0]["U_name"].ToString();
Label1.Text = m;
}
private DataTable getData() //构造getData()
{
SqlConnection con = new SqlConnection("data source=(localhost);database=OA;user id=sa;password=sa123");
SqlDataAdapter sa = new SqlDataAdapter("select top 1 * from T_UserInfo", con);
DataSet ds = new DataSet();
sa.Fill(ds);
return ds.Tables[0];
}}
adapter.SelectCommand = new SqlCommand(
queryString, connection);
adapter.Fill(dataset);
SqlCommand comm = new SqlCommand(sql,con)
SqlDataAdapter sa = new SqlDataAdapter(comm);
如:LUOBO-07807A113\SQLEXPRESS
con.open();
SqlDataAdapter sa = new SqlDataAdapter("select top 1 * from T_UserInfo", con);
把数据库连接打开