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