1

While I run my spring boot application, which is trying to store data into MS SQL server database, it is unable to connect to Microsoft SQL database.

I am getting the following exception while running:

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host /sqlexpress, port 1433 has failed. Error: "null. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".

In the code, in java class having main method, the bean method "dataSource()" is implemented as shown below:

@Bean public DataSource dataSource(){

    final DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    dataSource.setUrl("jdbc:sqlserver://<system_name>/sqlexpress:1433;databaseName=databasename");
    dataSource.setUsername("username");
    dataSource.setPassword("password");
    return dataSource;
}

I am trying to connect using JdbcTemplate. In gradle dependency, the following dependencies are added:

compile("org.springframework:spring-jdbc") compile("com.microsoft.sqlserver:sqljdbc4:4.0")

From Microsoft SQL Server 2014 Management Studio, I could connect to the host system_name/sqlexpress, having port 1433. I have checked the SQL server configuration manager --> SQL Server Network Configuration --> Protocols for SQLEXPRESS --> TCP/IP . It is enabled and in TCP/IP properties, TCP port of IPAll is set to 1433 only.

I couldn't identify why it is not getting connected when connection is trying from springboot application.

It is highly appreciable if you have any possible solution for this MSSQL connection issue.

Thanks

1 Answer 1

1

Basically you need to configure the TCP/IP in a hard coded way. How to do that is very well explaned here configuring SpringBoot for MSSQL :

  • From the Start menu, open SQL Server 2014 Configuration Manager.
  • Click Protocol for SQLEXPRESS under SQL Server Network Configuration on the left pane.
  • On the right pane, right- click TCP/IP, and select Properties.
  • On the TCP/IP Properties dialog box that appears, click the IP Addresses tab. Scroll down to locate the IPALL node.
  • Remove any value, if present for TCP Dynamic Ports and specify 1433 for TCP Port.
  • Now click OK and restart your SQL Server.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.