string one = "Data Source=wuchao159753-pc;Initial Catalog=UesrYan;Integrated Security=True";
            SqlConnection connection=new SqlConnection(one);
            int num;
            string message="";
            string sql = "SELECT COUNT(*) FROM UesrYan ";            try
            {
            connection.Open();
            SqlCommand command = new SqlCommand(sql,connection);
            num = (int)command.ExecuteScalar();
            message = string.Format("UesrYan表中共有(0)个用户",num);
            MessageBox.Show(message,"查询结果",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
            }catch(Exception ex){
                MessageBox.Show(ex.Message);
            }finally{
            connection.Close();
            MessageBox.Show("关闭数据库成功");在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - 无法打开到 SQL Server 的连接)
请各位大侠帮忙解析

解决方案 »

  1.   

    你sqlserver设置有问题,进外围应用配置器改成可以远程
      

  2.   

    UesrYan是数据名还是表名啊,我看你的数据库名和查询语句都用的是UesrYan,他们同名?
      

  3.   

    Initial Catalog代表数据库名称,先确定数据库名称是不是UesrYan
      

  4.   

    检查下你配置文件中的实例名跟数据库中的实例名是否一致。不知道你的SQL Server是否是Express版本的,是的话string one = "Data Source=wuchao159753-pc\Express;Initial Catalog=UesrYan;Integrated Security=True";
      

  5.   

    MS SQL服务跑起来了没?
    进入配置管理器,开命远程访问下的命名管道和TCP
    如果上面两项都没有问题,再看看连接字符串,检查杀软或防火墙是否有屏蔽SQL远程端口