I'm stucked in a problem during connection from my java project (play framework ) to a sql server database in Azure.
In local enviroment the connection works fine.
Below parameter in my application.conf :
db.default {
url="jdbc:sqlserver://server-name.database.windows.net:1433;database=database-name"
encrypt=true
trustServerCertificate=false
hostNameInCertificate="*.database.windows.net"
loginTimeout=30
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
username="root"
password="RootPwd"
}
This is the error received:
ERROR o.h.e.jdbc.spi.SqlExceptionHelper HikariPool-1 - Connection is
not available, request timed out after 30006ms. ERROR
o.h.e.jdbc.spi.SqlExceptionHelper The TCP/IP connection to the host
par-sql-server.database.windows.net, port 1433 has failed. Error:
"par-sql-server.database.windows.net. 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.". ERROR
p.api.http.DefaultHttpErrorHandler
play.api.PlayException: Execution exception[[CompletionException:
org.hibernate.exception.JDBCConnectionException: Unable to acquire
JDBC Connection]]
at play.api.http.HttpErrorHandlerExceptions$.$anonfun$convertToPlayException$3(HttpErrorHandler.scala:388)
at scala.Option.getOrElse(Option.scala:201)
at play.api.http.HttpErrorHandlerExceptions$.convertToPlayException(HttpErrorHandler.scala:388)
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:373)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:264)
at play.core.server.AkkaHttp
I have already checked that tcp/ip port 1433 is correctly available for database, and my ip is correctly setted to avoid firewall.
Any suggestions?
thanks
Usually this error occurs when the database is not getting the connection within the default connectionTimeout property.
You can try to increase the value of connectionTimeout in Java config as below:
config.setConnectionTimeout(300000);
below is one of the sample config:
HikariConfig config = new HikariConfig();
config.setMaximumPoolSize(20);
config.setConnectionTimeout(300000);
config.setConnectionTimeout(120000);
config.setLeakDetectionThreshold(300000);
If possible let me know the steps to reproduce this issue so that I can fix it accordingly, also based on the information you've provided these blogs (Blog1, Blog2) will help you in establishing the connection
Related
I am attempting to establish a connection to my local sqlserver instance on android with this line
Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:3306;DatabaseName=test", "admin", "password");
But I am getting this error
The TCP/IP connection to the host localhost, port 3306 has failed.
Error: "Connection refused. 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
I know that using jdbc to create direct database connections on android is not recommended for very good reasons, but that is not my concern right now.
I have verified in sql server configuration manager that tcp/ip is enabled for LOCAL and that IPAll TCP Port is set to 3306. I restarted the server after making these changes.
I have created a firewall rule allowing tcp/ip connections on port 3306 for local/domain connections inbound and outbound.
I checked the port with telnet telnet localhost 3306 and it connected.
Any help is appreciated, it is beginning to get frustrating.
This question already has answers here:
JDBC connection failed, error: TCP/IP connection to host failed
(9 answers)
Closed 5 years ago.
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. 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:191)
at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:242)
at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2369)
at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:551)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1963)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1628)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1459)
I'm facing this exception after I tried to connect with my driver through the new database profile.
The information I have was correct and the TCP port was enabled and the firewall was turned off.
I'm using Microsoft SQL server 2008 JDBC driver and I've added the jars.
A "connection refused" is rarely caused by the connecting client, i.e. the JDBC client within your Eclipse setup. A good check is to open a shell (e.g. cmd.exe on Windows) and do a
telnet [server name used in JDBC configuration] 1433
On newer Windows installations you need to install the telnet client because it's not part of the standard installation anymore (Settings -> Software -> Add/Remove Features).
If that leads to a similar error message you can focus your trouble shooting to the network part of your system, since the JDBC side is completely uninvolved. If you can connect, make sure that the server name resolves to the same IP when using the command prompt as it's resolved within Java (I once had this effect which took quite a time to find that out). Especially with localhost as server name one might resolve to 127.0.0.1 while the other resolvs to ::1.
I am trying to install "Kwok information server" and I am new to postgreSQL. I just followed the installation guide of Kwok information server.
when I am trying to install kwok-schema-setup.jar file using java through postgreSQL server in Command Prompt, I am getting the following error..."Connecting to PostgreSQL Server ...failed. Connection refused. Check that the ho
stname and port are correct and that the postmaster is accepting TCP/IP connecti
ons. Cause: java.net.ConnectException: Connection refused: connect
Schema setup encountered errors" .
And when I am trying to connect to the server using pgAdmin III, I am getting the following error "Server doesn't listen
The server doesn't accept connections: the connection library reports
could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432? ".
Please anyone help me regarding, Thanks in advance!!
Looks like your Postgresql daemon is not running. Check if the server has started and is running. I dont know which OS you are using but try ps -ax on linux/mac or the task manager in windows.
Maybe a firewall that is blocking the connection, you have to provide more information about your environment to be sure.
Currently I am working on a project using spring, hibernate with Microsoft SQL, in this project there is a part to generate invoice. When I run this part to generate invoice it take around 5 to 15 min then I retrieve invoice List from Db and show it in UI. I got exception after it process for around 7 to 10 min.
Note: When I check in Db , invoice is already generated.
How can I solve this issue?
The exception as follows:
org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.191.19, port 1433 has failed. Error: "Address already in use: connect. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".
I think the driver may be the problem.
Try using jtds driver instead of microsoft dirver.
Check your connection url pattern.Here is sample connection url pattern.
jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks;integratedSecurity=true;
I get a communication link failure while application tries to establish a connection with DB.
[#|2010-04-08T20:09:57.825+0300|SEVERE|glassfish3.0|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=24;_ThreadName=Thread-1;|Cannot connect to database server = com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.|#]
Precisely at this string:
Statement s = conn.createStatement();
where conn is defined as follows:
private static java.sql.Connection conn;
For this app I have set a connection pool with default parameters and currently it (app) uses both JPA and direct JDBC queries. Recreation of connection pool gave nothing, connection pool ping gave next message:
Ping Connection Pool for pool is Failed. Ping failed Exce
ption - Connection could not be allocated because: Communications lin
k failure%%%EOL%%%%%%EOL%%%The last packet sent successfully to the s
erver was 0 milliseconds ago. The driver has not received any packets
from the server. Please check the server.log for more details.%%%EOL
%%%Ping failed Exception - Connection could not be allocated because:
Communications link failure
and flushing the connection pool gave:
com.sun.enterprise.admin.cli.CommandException: remote failure: Failed to flush connection pool ...
However I can connect to the database from a terminal. Besides I have the same app working on my local machine with identical connection pool settings.
Any one has an idea on whats going on or how to solve the trouble?
Such problem could be if you have mysql server & glassfish server on the same host, and in mysql configuration you have option bind to some public address (for example 192.168.0.1 of eth0 interface) that normally successfully working with simple jdbc/jpa using user#localhost, but they don`t in a case of glassfish JTA, instead to bind to some of local address you getting link failure. As rule you could not bind to any local (localhost/127.0.0.1) addresses of such mysql host if public address presented.
Example:
my.cnf
bind-address = 127.0.0.1
bind-address = 192.168.0.1
127.0.0.1 - assign to lo interface
192.168.0.1 - assign to eth0 interface
It is glassfish-mysql bug.
Currently in order to use JTA, you should not bind mysql to such address. (remove "bind-address=192.168.0.1" from my.cnf). Or use user#192.168.0.1 what is less secure.
Besides I have the same app working on my local machine with identical connection pool settings.
Are you connecting to the same database? If yes, maybe check that you're using the same JDBC driver.
In my case I set :
URL : jdbc:mysql://10.81.35.66:3306/testDB
and
url : jdbc:mysql://10.81.31.76:3306/vectordb
both When setting values while creating connection pool in additional property part
on glass fish admin console .