标题: 连接到服务器
------------------------------
我使用Sql Server 2008 Express R2,
安装好数据库和Sql Sever Management stdio。
使用 Management stdio 链接 “数据库引擎(local)”,使用两种验证方式,都出现以下错误,请教如何解决。
无法连接到 (local)。在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接) (Microsoft SQL Server,错误: 2)

解决方案 »

  1.   

    参照2005的方法去设置。
    Sql Server 2005的1433端口打开和进行远程连接
    如何打开sql server 2005 的1433端口配置工具->Sql Server Configuration Manager->MSSQLSERVER的协议看看TCP/IP协议是否启动,如果启动,右键菜单点"属性" ,在分页菜单中选"IP地址",把"IP1"和"IP2"中"TCP端口"为1433,"已启用"改为"是"配置工具->Sql Server Configuration Manager->SQL Native Client 配置->客户端协议->TCP/IP选择TCP/IP右键菜单中"属性",确认"默认端口"是1433,"已启用"为"是"
    SQL Server 2005 远程连接配置TCP/IP属性. 
    Surface Area Configuration --> Database Engine --> Remote Connections --->Using TCP/IT SQL Server 外围应用配置器—服务和连接外围配置—database englie—远程连接—启用(远程连接的TCP/IP和named pipes)  
    SQL Server Configuration Manager—SQL2005网络配置—启用TCP/IP和named pipes
    -----------------------------------------------------------------------------------------
    一般按如上即可. 其他说明见下: 
    sqlserver2005(Express版),为了便于管理,你还需要去下一个manage管理器,微软的官方网站有 
    下,安装好manage管理器后,在程序中连接sqlserver2005,下面几点是要注意的。 
          1. 开启sql2005远程连接功能,开启办法如下, 
              
    配置工具->sql 
    server外围应用配置器->服务和连接的外围应用配置器->打开MSSQLSERVER节点下的Database Engine 
    节点,先择"远程连接",接下建议选择"同时使用TCP/IP和named pipes",确定后,重启数据库服务就可以了. 
          2.登陆设置改为,Sql server and windows Authentication方式同时选中,具体设置如下: 
            
    manage管理器->windows 
    Authentication(第一次用windows方式进去),->对象资源管理器中选择你的数据服务器--右键>属 
    性>security>Sql server and windows Authentication方式同时选中. 
          3:设置一个Sql server方式的用户名和密码,具体设置如下: 
        manage管理器->windows Authentication>new query>sp_password null,'sa123456','sa' 
        这样就设置了一个用户名为sa ,密码为:sa123456的用户,下次在登陆时,可以用Sql server方式, 
    用户名为sa ,密码为:sa123456的用户进数据库了. 
          4: 做完上面三步后,这样写连接字符串就可以顺利进入数据库了, 
            (server=.\\sqlexpress;uid=sa;pwd=sa123456;database=master"; 
    其它版本,做如下設置 程序—Microsoft SQL Server 2005—配置工具—SQL Server 外围应用配置器—服务和连接的外围应用配置器— 
    1、MSSQLserver(实例名)—DataBase Engine—远程连接—(设置选项) 
    在下方选项 
    2、SQL Server Browser—服务(停止时只本机访问) 
    3、程序—Microsoft SQL Server 2005—配置工具—SQL Server Configuration Manager—网络连接协议-选择实例对应协议—启用(shard memory、Named Pipes、TCP\IP) 
    注: SQL Server 浏览器程序以服务的形式在服务器上运行。SQL Server 浏览器侦听对 Microsoft SQL Server 资源的传入请求,
    并提供计算机上安装的 SQL Server 实例的相关信息。
    SQL Server 浏览器可用于执行下列三种操作: 
    浏览可用服务器 
    连接到正确的服务器实例 
    连接到专用管理员连接 (DAC) 端点 
    SQL Server Browser 服务 (sqlbrowser) 为数据库引擎 和 SSAS 的每个实例提供实例名称和版本号。
    SQL Server 浏览器随 Microsoft SQL Server 2005 一起安装,
    为该计算机上运行的早期版本的 SQL Server(从 Microsoft SQL Server 7.0 开始)提供此服务。
      

  2.   

    按dawugui的方法处理,还是不行,用netstat -an检查1433端口未打开,
    Management studio使用windows身份验证登录,也是不行。
    不知什么原因。删除Express,重新安装标准版,一切正常!看来MS还是鼓励盗版。
      

  3.   

    winerr 2 means "The system cannot find the file specified". This error message means the client can reach the server but there is no Named Pipe listener with specific pipe name on the target machine. It also means the account can have a file sharing session without a problem.Possible reasons are:
     a) typo in instance name or wrong instance name. The instance name is not the one you are targeting. Note that for default instance, you shouldn't use MSSQLSERVER as instance name.
     b) Target SQL Server is not running
     c) Named Pipe is not enabled on the server. In this case, the SQL server is not listenning on the specific pipe name. 
      

  4.   

    Server is running
    Named Pipe is enabled
    但问题依旧