ERROR: TCP/IP connection to host localhost via port 1433 failed. Error: "Connection refused:connect. Verify the connection properties and check that instances of SQL Server are running on the host and that the TCP/IP connection is accepted on this port, and that the firewall does not block TCP connections to this port. ”。
Recently to learn the database, the teacher with Microsoft SQL Server 2005, I was learning Java, has been JDBC to connect to the Oracle database, this time I installed Microsoft SQL Server 2005, want to use JDBC to connect Microsoft SQL Server 2005 did not come up with such a problem:
com.microsoft.sqlserver.jdbc.sqlserverexception: connects to the host via port 1433 localhost TCP/IP connection failed for . Error: "Connection refused:connect. Verify the connection properties and check that an instance of sql server is running on the host and that the port accepts TCP/IP connections, and that the firewall does not block TCP connections to this port. ”。
at Com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError (sqlserverexception.java:171)
at Com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper (sqlserverconnection.java:1033)
at Com.microsoft.sqlserver.jdbc.SQLServerConnection.login (sqlserverconnection.java:817)
at Com.microsoft.sqlserver.jdbc.SQLServerConnection.connect (sqlserverconnection.java:700)
at Com.microsoft.sqlserver.jdbc.SQLServerDriver.connect (sqlserverdriver.java:842)
at Java.sql.DriverManager.getConnection (drivermanager.java:582)
at Java.sql.DriverManager.getConnection ( drivermanager.java:185)
at Com.luoying.TestSQLServer2.main (testsqlserver2.java:15)
The reason: the TCP/IP protocol for the SQ server Express version is disabled by default, so the SQL Server Management Studio client can connect, but the Java program connection fails.
Workaround: Enable the TCP/IP protocol
Note: If you cannot find the SQL Server Configuration Management (Configuration Management tool), follow these steps:
to open SQL Server Configuration Manager, in the Search Super button, under Application, type SQLSERVERMANAGER11.MSC (for SQL Server 2012) or Sqlservermanager10.msc (for SQL Server 2008), and then press the ENTER key. As shown in the following illustration: