[Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.1、winXP sp2系统安装SQL Server2000标准版;2、混合认证模式;2、已安装SQL Server2000 sp3;3、已安装JDBC SP3;4、查看SQL Server服务器和客户机默认端口均为1433;5、命令窗口中使用telnet 1433命令,错误如下:
   正在连接到localhost:1433...不能打开到主机的连接, 在端口 23: 连接失败;程序如下:public class test { public static void main(String[] args) throws ClassNotFoundException {
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
      String url    = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName =test";
         Class.forName(driver);
         System.out.println("Driver is OK");//输出正常
         try {
Connection conn = DriverManager.getConnection(url,"sa","sa");//错误
System.out.println("Connect to DBMS is OK!");
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

解决方案 »

  1.   

    ur firewall?--------------------"Error establishing socket" exception while connecting to the database
    Symptom: while running a windows application that includes massive opening and closing of a connections to database server, "Error establishing socket" exception appears after a short time of execution.Cause: This problem is caused by a lack of a reusable sockets on client machine, since each TCP/IP connection stays in the TIME_WAIT state when the connection is being closed. While a connection is in this state, the socket cannot be reused.Resolution: do one of the following:Increase the port range that is used for anonymous ports to approximately 20,000 ports (for example) by modifying the MaxUserPort registry key (this parameter controls the maximum port number that is used when an application requests any available user port from the system). Windows uses the conventional BSD range of 1024 to 5000 for its anonymous (ephemeral) port range. You can set only the upper bound of the ephemeral port range. To modify the MaxUserPort registry key, follow these steps:
    Start Registry Editor (Regedt32.exe). Please note that you should backup your registry and any important files on your computer before editing the registry.
    Locate the MaxUserPort key in the registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
    On the Edit menu, click Add Value, and then add the following registry value:
    Value Name: MaxUserPort
    Data Type: REG_DWORD
    Value: 65534 (for example)
    Valid Range: 5000-65534 (decimal)
    Default: 0x1388 (5000 decimal)
    Quit Registry Editor.
    Change the timeout on the connections from 240 seconds (the default) to any length from 30 seconds to 300 seconds. Use the TcpTimedWaitDelay registry parameter to change this value. To do this, start Registry Editor (Regedt32.exe), locate the following key in the registry, and then modify the value HKEY_LOCAL_MACHINE\System\CurrectControlSet\services\Tcpip\Parameters (this parameter determines the length of time that a connection stays in the TIME_WAIT state when the connection is being closed. While a connection is in the TIME_WAIT state, the socket pair cannot be reused. For more information, see RFC 793):
    Value Name:TcpTimedWaitDelay
    Value Type: REG_DWORD-time in seconds
    Valid Range: 30-300 (decimal)
    Default: 0xF0 (240 decimal)
    More information available at http://support.microsoft.com/default.aspx?scid=kb;EN-US;319502
      

  2.   

    防火墙限制?
    3个JDBC包没打进去?
      

  3.   

    SQL SERVER 2000要打sp3以上的补丁,驱动也要用对应的版本才可以连上
      

  4.   

    第一步,看sql server是否能正常启动
    二步:按装数据源sp3驱动,
    三步,将数据源驱动下的msbase,mssqlserver,msutil这三个文件拷到你的工程文件下
    四:ok
      

  5.   

    我都按照楼上的做了,可是还是不行!
    命令窗口中使用telnet 1433命令,错误如下:
       正在连接到localhost:1433...不能打开到主机的连接, 在端口 23: 连接失败;
    这个怎么解决???
      

  6.   

    上面说的就不是解决你问题的方法
    1、 服务器正常启动检查是不是使用1433 端口
    2、查看防火墙是不是屏蔽1433端口了
    3、CMD-NETSTAT -AN 检查下你的1433端口是不是开启 没有的话 打SQL SERVER 的补丁 SP3 OR SP4 基本都是补丁问题
     LZ可以揭贴了。
      

  7.   

    我也是遇到了这种情况,用netstat -an查到139端口开放,我只好把SQLServer2000的默认端口号改为139,但目前是SQL Server数据库通过jdbc-odbc桥可以连通,用上述方式还是会出错,并在程序数据库连接的程序运行中出现的如下提示:[Microsoft][SQLServer 2000 Driver for JDBC]The requested instance is either invalid or not running.但是我的SQL Server 2000服务器明明已经开启,而且实例也配置过了.不晓得是不是这个端口是开放给其他的服务用了?还有就是我试过了,即使是关闭了防火墙,1433端口依旧是登录不了,是不是Xp系统下才会出现这种问题呢?关注中...
      

  8.   

    windows203+sql server 2000无法打开1433端口
    1.如果你是win2003,那么一定要安装sql的补丁sp3a检查你的SQL有没有打补丁,没有的话要打上补丁,检查的方法是在查询分析器中运行:
    select @@version
    如果出来的版本号是8.00.760以下,则表明你未安装sp3的补丁,要装上.详细请看:http://www.i170.com/user/power/Article_24904
      

  9.   

    按 xizhiyao(流浪的猴子) 说的做。
      

  10.   

    我发现自己在安装SQLServer2000 SP4时,犯了一个超级傻瓜的错误,一直以为下来的就是安装程序,点击运行就完事了.现在回过头来在查询分析器里一看,原来一直就没有更新过,我到安装的目录下一看,原来只是执行解压,并没有去做安装操作.于是就把setup.bat程序执行一下,才真正做了更新的安装操作.安装完毕,重启机后,在命令行下运行telnet 127.0.0.1 1433,发现端口打开了,程序正常运行,问题解决啦!楼主不妨也查看一下自己的补丁是否真正打上?
      

  11.   

    我是一个学习编程的,也遇到了上面的问题,用了 jhy2003hn  的解决办法,就可以了
    谢谢 jhy2003hn  
      

  12.   

    打上了SP4后就OK了,不过不要犯和 jhy2003hn 一样的错误哦
      

  13.   

    那个setup.bat文件在哪里啊,我怎么找不到呢。
      

  14.   

    我的数据库开始安装时就是windows认证模式,现在在java中连接数据库怎么填那用户名和密码?
      

  15.   

    如果经常遇到这种问题呢,我建议换个驱动得了,不用原来的三个纯驱动包了,改成jtds驱动试试....详细请百度jtds.