26
votes

I'm getting this 2 errors repeatedly when I'm trying to connect eclipse with sql server through jdbc. Could anyone help me with this or explain why am I getting this?

1. The TCP/IP connection to the host localhost, port 1433 has failed.  
2. The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption.

Thank you.

String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
Class.forName(driver).newInstance();
String connString      ="jdbc:sqlserver://localhost:1433/databaseName=Engg_Street;instance=SQLSERVER;encrypt=true;     trustServerCertificate=true";
String username = "Vijayalakshmi";
String password = "";
conn = DriverManager.getConnection(connString,username,password);
3
Well, the error is quite clear: JDBC can't connect to your database using SSL. Is your database configured to use SSL on port 1433?Stefan
Any code you are using? Help us to help you.qiGuar
Hey I have posted the code in my new ques,can you help??Navin Kumar
@user2810964 - Don't do that! Edit this Question to add your code here!Stephen C
@Stephen C Yes I have done it..Navin Kumar

3 Answers

54
votes
You need to Go to Start > Microsoft SQL Server > Configuration Tools > SQL Server Configuration Manager

When it opens Go to

SQL Server Configuration Manager > SQL Server Network Configuration > Protocols for SQLExpress 

Where you'll find the Protocol TCP/IP, if disabled then Enable it Click on TCP/IP, You'll find its properties.

In this properties Remove All the TCP Dynamic Ports and Add value of 1433 to all TCP Port and restart your SQL Server Services > SQL Server

And Its Done...

1
votes

For this kind of issue - you can resolve by checking whether all sql server related services are running or not.

TO check Start -> Run -> services.msc 
check services related to sql as
SQL Server (MSSQLSERVER)
SQL Server Agent (MSSQLSERVER)
SQL Server Analysis Services (MSSQLSERVER)
SQL Server Browser
SQL Server Integration Services 10.0
SQL Server Reporting Services (MSSQLSERVER)
SQL Server VSS Writer

Start all the above services. and set to start up type to Automatic.

SQL Active Directory Helper Service is not required to keep running.

It can used to deal with error SQL server connection error 2 and with he TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused:

1
votes

If you are running SQLSERVER EXPRESS:

Use "SQL Server Configuration Manager" or write "mmc.exe" on Win+R and search "SQL Server Network Configuration", in the "Protocols for SQLEXPRESS" enable the option TCP/IP

I hope than this works for somebody!!