求助...! 请求帮助。jdbc连接sqlserver 2008 出现错误

刘轩麟 发布于 2014/03/20 12:14
阅读 1K+
收藏 0

又出了一个问题  希望大家帮帮忙谢谢!  错误如下

com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“驱动程序收到意外的登录前响应。请验证连接属性,并检查 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接。该驱动程序只能与 SQL Server 2000 或更高版本一起使用。”。

做过修改: 

1.改过配置管理器的ip端口    但是将IPALL;TCP端口改为1433后    实例就无法启动了 动态端口改为0也一样 
2.用的是sqlserver 2008  在数据库方面里找到外围配置器   没有2005里的TCP/IP和namepath同时使用.

3。客户协议中的 默认端口也改为了 1433 并且已启用   VIA 改为了已禁用;

 

完整报错为;

{2014-3-19 12:08:12 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 50f4a5d8-bb6f-4f99-8d7b-adfe2e80563f Prelogin error: host localhost port 1433 Unexpected response type:72
2014-3-19 12:08:12 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 0a1dd328-dada-4080-bc06-be04ccc453c0 Prelogin error: host localhost port 1433 Unexpected response type:72
2014-3-19 12:08:12 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 622c00d1-0248-4e8c-a3e5-3eb688aa6379 Prelogin error: host localhost port 1433 Unexpected response type:72
2014-3-19 12:08:13 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 4123a5bb-e5f7-4328-ac6f-4cb79c4928dd Prelogin error: host localhost port 1433 Unexpected response type:72
2014-3-19 12:08:14 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: a60a3276-14bb-4813-8ba2-bcb8efcaa687 Prelogin error: host localhost port 1433 Unexpected response type:72
2014-3-19 12:08:15 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 88b6198b-3f12-47a3-99f2-e7a81c9a5c9e Prelogin error: host localhost port 1433 Unexpected response type:72
2014-3-19 12:08:16 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 054c08fa-61c9-4771-9b7c-486e4c5518c8 Prelogin error: host localhost port 1433 Unexpected response type:72
2014-3-19 12:08:17 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 5241346b-a37c-4d12-91b9-4deb5fa26bed Prelogin error: host localhost port 1433 Unexpected response type:72
2014-3-19 12:08:18 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 530fbfd8-11af-4662-aa1b-e7a89b27d334 Prelogin error: host localhost port 1433 Unexpected response type:72
2014-3-19 12:08:19 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: ae44683a-fc97-45f3-b85d-5207ab464b02 Prelogin error: host localhost port 1433 Unexpected response type:72
2014-3-19 12:08:20 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: e4aa1506-7f30-4890-81a2-efeb38d7fb18 Prelogin error: host localhost port 1433 Unexpected response type:72
2014-3-19 12:08:21 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: f88b2bae-3251-4668-a6f3-938feb366f11 Prelogin error: host localhost port 1433 Unexpected response type:72
2014-3-19 12:08:22 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 6da0aa50-f5f6-44d6-9582-97d81aa8cd0a Prelogin error: host localhost port 1433 Unexpected response type:72
2014-3-19 12:08:23 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 1c7e1186-1ee1-4dc4-8a20-7f4ca779ce53 Prelogin error: host localhost port 1433 Unexpected response type:72
2014-3-19 12:08:24 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 31409ef0-8c9f-453b-b3a5-cace8577b1d4 Prelogin error: host localhost port 1433 Unexpected response type:72
2014-3-19 12:08:25 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 643c6af3-c779-4fd1-be52-4cf27dd9d0e1 Prelogin error: host localhost port 1433 Unexpected response type:72
2014-3-19 12:08:26 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 13d38fa8-af88-4b58-952a-fb77f0a90e9b Prelogin error: host localhost port 1433 Unexpected response type:72
com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“驱动程序收到意外的登录前响应。请验证连接属性,并检查 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接。该驱动程序只能与 SQL Server 2000 或更高版本一起使用。”。 ClientConnectionId:13d38fa8-af88-4b58-952a-fb77f0a90e9b
 at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1667)
 at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1654)
 at com.microsoft.sqlserver.jdbc.SQLServerConnection.Prelogin(SQLServerConnection.java:1464)
 at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1319)
 at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
 at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
 at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
 at java.sql.DriverManager.getConnection(DriverManager.java:582)
 at java.sql.DriverManager.getConnection(DriverManager.java:207)
 at rr.main(rr.java:19)
}

代码为;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;


public class rr {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
   Connection ct = null;
     Statement sm = null;
     ResultSet rs = null;
     try {
      Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
      ct = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;database=ggg");
      sm = ct.createStatement();
      rs = sm.executeQuery("select * from eee");
      while(rs.next()) {
        String b=rs.getString(1)  

System.out,println(b);

  }
     }catch (Exception e) {
      e.printStackTrace();
     }finally {
      try {
       if(rs != null) {
        rs.close();
        rs = null;
       }
       if(sm != null) {
        sm.close();
        sm = null;
       }
       if(ct != null) {
        ct.close();
        ct = null;
       }
      }catch (Exception e) {
       e.printStackTrace();
      }
     }
 }

}

 

加载中
返回顶部
顶部