Angelina
Angelina

Reputation: 2265

Cannot initialize database connection from spring boot application

I am able to successfully connect to my local database, by specifying following URL in application.properties file of my spring boot application:

application.properties

spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=mantaDB;integratedSecurity=true

And here is my output:

2019-Aug-29 11:14:41.298    INFO  com.zaxxer.hikari.HikariDataSource   - HikariPool-1 - Starting... -   
2019-Aug-29 11:14:41.753    INFO  com.zaxxer.hikari.HikariDataSource   - HikariPool-1 - Start completed. -   
2019-Aug-29 11:14:41.914    INFO  o.h.jpa.internal.util.LogHelper   - HHH000204: Processing PersistenceUnitInfo [_  name: default_  ...] -   
2019-Aug-29 11:14:42.102    INFO  org.hibernate.Version   - HHH000412: Hibernate Core {5.3.7.Final} -    
2019-Aug-29 11:14:42.396    INFO  o.h.annotations.common.Version   - HCANN000001: Hibernate Commons Annotations {5.0.4.Final} -   
2019-Aug-29 11:14:42.827    INFO  org.hibernate.dialect.Dialect   - HHH000400: Using dialect: org.hibernate.dialect.SQLServerDialect -   
2019-Aug-29 11:14:44.157    INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean   - Initialized JPA EntityManagerFactory for persistence unit 'default' -  

Now, I want to change application to point to my dev db box:

application.properties

spring.datasource.url=jdbc:sqlserver://STUDENT12.site,28001;databaseName=mantaDB;integratedSecurity=true

But, I am getting following error:

2019-Aug-29 11:16:48.089    INFO  com.zaxxer.hikari.HikariDataSource   - HikariPool-1 - Starting... -   
2019-Aug-29 11:17:18.682    ERROR com.zaxxer.hikari.pool.HikariPool   - HikariPool-1 - Exception during pool initialization. -   
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host STUDENT12.site,28001, port 1433 has failed. Error: "STUDENT12.site,28001. 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.".
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:228)
    at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:285)

Clearly, I can get to the database.

Does anyone know what i am doing wrong?

Upvotes: 0

Views: 1150

Answers (1)

David Browne - Microsoft
David Browne - Microsoft

Reputation: 88851

The JDBC Url should look like:

jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]

Building the Connection URL

And the error makes it clear that you are not connecting on port 28001:

connection to the host JD1LSTWLSLMC101.dcsr.site,28001, port 1433 has failed

So

spring.datasource.url=jdbc:sqlserver://JD1LSTWLSLMC101.dcsr.site:28001; . . .

Upvotes: 2

Related Questions