在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接)

解决方案 »

  1.   

    了解字面意思!查看SQL2005有无正常运行!!
      

  2.   

    没有连接到服务器或者服务器不允许连接。你的帐户权限开了的吗?SQL Server Management Studio Express
      

  3.   

    在SQL 2005 外围程序里面把 TCP和named打开
      

  4.   

    sql server2005的问题!!
    你试试看看能不能连接数据库!!
      

  5.   

    你把你的连接字符串发出来看看你用SQL Server Management Studio Express-服务器右键属性-安全性-选择sqlserver和windows模式,失败和成功的登录。在选择连接 勾上 允许远程连接此服务器
      

  6.   

                string Afile = "server=PK-PC;uid=pk;pwd=123456;database=成绩表";
                SqlConnection conn = new SqlConnection(Afile);
                SqlDataAdapter da = new SqlDataAdapter("select 姓名,语文,数学,英语", conn);
                conn.Open(); 
                DataTable dt = new DataTable();
                da.Fill(dt);
                this.textBox1.Text = dt.Rows[1]["姓名"].ToString();
                this.textBox2.Text = dt.Rows[1]["英语"].ToString();
                this.textBox3.Text = dt.Rows[1]["语文"].ToString();
                this.textBox4.Text = dt.Rows[1]["数学"].ToString();
                da.Dispose();
                conn.Close();
                conn.Dispose();
      

  7.   

    Data Source=SERVER\SQLSERVER2005;Initial Catalog=数据库;Persist Security Info=True;User ID=sa;PassWord=sa
      

  8.   

                string Afile = "server=PK-PC;uid=pk;pwd=123456;database=成绩表"; //有问题
                SqlConnection conn = new SqlConnection(Afile); 
                SqlDataAdapter da = new SqlDataAdapter("select 姓名,语文,数学,英语", conn); //有问题
                conn.Open(); 
                DataTable dt = new DataTable(); 
                da.Fill(dt); 
                this.textBox1.Text = dt.Rows[1]["姓名"].ToString(); 
                this.textBox2.Text = dt.Rows[1]["英语"].ToString(); 
                this.textBox3.Text = dt.Rows[1]["语文"].ToString(); 
                this.textBox4.Text = dt.Rows[1]["数学"].ToString(); 
                da.Dispose(); 
                conn.Close(); 
                conn.Dispose();
    你改成
    string Afile = "Data Source=服务器名;Initial Catalog=数据库;Persist Security Info=True;User ID=用户名;PassWord=密码";SqlDataAdapter da = new SqlDataAdapter("select 姓名,语文,数学,英语 from 你的表", conn)
      

  9.   

    string Afile = "server=PK-PC;uid=pk;pwd=123456;database=成绩表"; 你把database=成绩表"; 换成database=数据库名;
      

  10.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    namespace 查询
    {
        public partial class Form1 : Form
        {
          
            
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
            }        private void button2_Click(object sender, EventArgs e)
            {
                SqlConnection conn = new SqlConnection("server=9aa7107a8cbe4fa;uid=jfq;pwd=123456;database=chengjibiao");
         
                    conn.Open();
                    SqlDataAdapter da = new SqlDataAdapter("select 姓名,数学,英语,语文 from 成绩表", conn);                DataTable dt = new DataTable();
                    da.Fill(dt);
                    
                        this.textBox1.Text = dt.Rows[1]["数学"].ToString();
                        this.textBox2.Text = dt.Rows[1]["语文"].ToString();
                        this.textBox3.Text = dt.Rows[1]["姓名"].ToString();
                        this.textBox4.Text = dt.Rows[1]["英语"].ToString();
                        
                    
                    da.Dispose();
                    conn.Close();
                    conn.Dispose();
              
                          }        private void button1_Click(object sender, EventArgs e)
            {
            }        private void textBox2_TextChanged(object sender, EventArgs e)
            {        }
        }
    }
      

  11.   

    DataTable dt = new DataTable(); 
    DataSet dt=new DataSet();
    这样看看
      

  12.   

    只有数据集dataset才能填充SqlDataAdapter 的对象