SQL exception when connecting to SQL server

I know this is a recurring question. I found very similar questions and solutions for them, but still I am amazed at this.

I am using eclipse to connect my java application with a Microsoft SQL Server 2008 database. Below is my code

import java.sql.*; public class ConnectionTest2 { public static void main(String [] args) { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=Sample;integratedSecurity=true"; Connection con = DriverManager.getConnection(connectionUrl,"",""); System.out.println("Connected"); } catch (SQLException e) { System.out.println("SQL Exception: "+ e.toString()); } catch (ClassNotFoundException cE) { System.out.println("Class Not Found Exception: "+ cE.toString()); } } } 

I enabled tcp / ip and VIA by going to the sql server configuration configurator and setting the port number to 1433 under IPALL.

I tried in many ways, but I can not find a solution to the following error

SQL exception: com.microsoft.sqlserver.jdbc.SQLServerException: TCP / IP connection to the local host, port 1433 failed. Error: "Connection refused: connect. Check the connection properties. Make sure that the instance of SQL Server is running on the host and accepting TCP / IP connections on the port. Make sure that TCP connections to the port are not blocked by the firewall.".

I also turned off Windows Firewall, but could not connect.

Please help me.

+2
java sql-server-2008 jdbc
Apr 05 2018-12-12T00:
source share
2 answers

This is what he says: connection refused. Have you tried "telnet 1433"?

+2
Apr 05 2018-12-12T00:
source share

I had this problem and fixed it by enabling TCP / IP for the server instance. You can do it with

  • Open SQL Server Configuration Manager
  • Expand SQL Server Network Configuration
  • Select Protocols for MSSQLSERVER
  • Enable TCP / IP

After that, you need to restart the SQL Server service to make it effective.

+3
Aug 03 2018-12-12T00:
source share



All Articles