com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口1433 连接到主机localhost 的TCP/IP 连接失败。错误:“Connection refused: connect。请验证连接属性。确保SQL Server 的实例正在主机上运行,且在此端口接受TCP/IP 连接,还要确保防火墙没有阻止到此端口的TCP 连接。”。
atcom.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
atcom.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:241)
at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2243)
atcom.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:491)
atcom.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1309)
atcom.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
atcom.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
atcom.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
atjava.sql.DriverManager.getConnection(DriverManager.java:185)
首先可以用cmd里面的telnet测试连接一下localhost 1433,出现连接失败,说明端口没打开,进
讲TCP/IP设为启用,然后重启SQL Server服务即可