I am trying to connect to SQL DB from Unix server. I have written a Java program for the same and complied in jre6.0 and using sqljdbc4-2.0.jar. But when I try to my jar in Unix server I get the below error:
com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "SQL Server did not return a response. The connection has been closed.".
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1368)
at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1412)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1058)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
at java.sql.DriverManager.getConnection(DriverManager.java:419)
at java.sql.DriverManager.getConnection(DriverManager.java:467)
at com.tgt.ttedb.TTEDatabaseUpdate.main(TTEDatabaseUpdate.java:31)
Caused by: java.io.IOException: SQL Server did not return a response. The connection has been closed.
at com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.ensureSSLPayload(IOBuffer.java:513)
at com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.readInternal(IOBuffer.java:570)
at com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.read(IOBuffer.java:562)
at com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream.readInternal(IOBuffer.java:757)
at com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream.read(IOBuffer.java:745)
at com.ibm.jsse2.b.a(b.java:215)
at com.ibm.jsse2.b.a(b.java:18)
at com.ibm.jsse2.SSLSocketImpl.a(SSLSocketImpl.java:215)
at com.ibm.jsse2.SSLSocketImpl.h(SSLSocketImpl.java:693)
at com.ibm.jsse2.SSLSocketImpl.a(SSLSocketImpl.java:535)
at com.ibm.jsse2.SSLSocketImpl.startHandshake(SSLSocketImpl.java:710)
at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1379)
Related
Trying to connect o MS SQL server that runs on the same Win 10 machine with my project in Eclipse:
String url = "jdbc:sqlserver://GOLD\\SQLEXPRESS;databaseName=PrintLog;";
Connection conn = DriverManager.getConnection(url ,"user","passwd");
But got exception:
com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host GOLD, named instance sqlexpress failed. Error: "java.net.SocketTimeoutException: Receive timed out". Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434. For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host.
Computer name is GOLD. I can connect to DB from C# without problem. Authentication is enabled both windows and SQL server. I'm expecting to get Windows authentication while connect
SQL server properties:
How to find the problem?
UPD
I got better result by adding port number to connect string:
String url = "jdbc:sqlserver://GOLD\\SQLEXPRESS:1433;databaseName=PrintLog;";
Does it means that default port number is different?
I have a Java application running as a WebJob on Azure. This job tries to connect to my Azure SQL Server. If the encryption is on, I get a connection error:
The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "java.security.cert.CertificateException: Failed to validate the server name in a certificate during Secure Sockets Layer (SSL) initialization.".
If encrypt = false it connects fine.
Shouldn't the communication between resources in Azure always be encrypted?
Also, if I run the application locally, the database connection successfully connects in encrypted mode.
First- I should explain that Azure SQL DB is always going to default to an encrypted connection. The error you're seeing is speaking of verifying the identity of the server that you're communicating with as part of the handshake for SSL. [There's some unpacking of this idea over here.] (https://security.stackexchange.com/questions/1779/how-does-an-ssl-server-prove-its-identity)
I unpacked the encryption of communication with Azure SQL Database in answers on this MSDN thread- but I'll bring the relevant portion here:
When using Azure SQL DB, connections are encrypted even when the connection
string does not include those portions we recommend.
...
Encryption occurs only if there is a verifiable server certificate,
otherwise the connection attempt fails.
Your error, as outlined on this MSDN article, arises from the following situation:
If the encrypt property is set to true and the trustServerCertificate
property is set to false and if the server name in the connection string
does not match the server name in the SQL Server SSL certificate, the
following error will be issued: The driver could not establish a secure
connection to SQL Server by using Secure Sockets Layer (SSL) encryption.
Error: "java.security.cert.CertificateException: Failed to validate the
server name in a certificate during Secure Sockets Layer (SSL) initialization."
Apparently, the JDBC driver for SQL Server 4.0 seems to resolve this error:
Azure VM Fails to Connect to Azure SQL Service
Certificate Exception connecting to Azure SQL with JDBC with default connection string (the one the management console says to use)
I'm getting an error in IntelliJ IDEA when im using a thin connection from java to oracle.
My oracle database is in a server and I can ping the server but my code can't establish connection:
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection("jdbc:oracle:thin:#server ip:1521:orcl","user","path");
System.out.println("Oracle Registered...");
and error is:
java.sql.SQLRecoverableException: IO Error: Socket read timed out
oracle.net.ns.NetException: Socket read timed out
It is possible that the network is reachable but the operations take too much time.
Check if you can establish a connection using a standard db client like toad, sql server or squirrel.
If you can use the same paramters in java and it should work.
If you can't check if another process is using port 1521 on the server.
I am getting the following error while connecting to the MS SQL 2008 R2 from a specific server, from other severs it works fine.
com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "SQL Server returned an incomplete response. The connection has been closed.".
The following is my code to connect to the database:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(db_info, db_userid, db_password);
I'm getting this 2 errors repeatedly when I'm trying to connect eclipse with sql server through jdbc. Could anyone help me with this or explain why am I getting this?
1. The TCP/IP connection to the host localhost, port 1433 has failed.
2. The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption.
Thank you.
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
Class.forName(driver).newInstance();
String connString ="jdbc:sqlserver://localhost:1433/databaseName=Engg_Street;instance=SQLSERVER;encrypt=true; trustServerCertificate=true";
String username = "Vijayalakshmi";
String password = "";
conn = DriverManager.getConnection(connString,username,password);
You need to Go to Start > Microsoft SQL Server > Configuration Tools > SQL Server Configuration Manager
When it opens Go to
SQL Server Configuration Manager > SQL Server Network Configuration > Protocols for SQLExpress
Where you'll find the Protocol TCP/IP, if disabled then Enable it Click on TCP/IP, You'll find its properties.
In this properties Remove All the TCP Dynamic Ports and Add value of 1433 to all TCP Port
and restart your SQL Server Services > SQL Server
And Its Done...
If you are running SQLSERVER EXPRESS:
Use "SQL Server Configuration Manager" or write "mmc.exe" on Win+R and search "SQL Server Network Configuration", in the "Protocols for SQLEXPRESS" enable the option TCP/IP
I hope than this works for somebody!!
For this kind of issue - you can resolve by checking whether all sql server related services are running or not.
TO check Start -> Run -> services.msc
check services related to sql as
SQL Server (MSSQLSERVER)
SQL Server Agent (MSSQLSERVER)
SQL Server Analysis Services (MSSQLSERVER)
SQL Server Browser
SQL Server Integration Services 10.0
SQL Server Reporting Services (MSSQLSERVER)
SQL Server VSS Writer
Start all the above services. and set to start up type to Automatic.
SQL Active Directory Helper Service is not required to keep running.
It can used to deal with error SQL server connection error 2
and
with
he TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused:
It can used to deal with error SQL server connection error 2 and with he TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: https://www.youtube.com/watch?v=R8_jjkeulEw
or please check if the table name is duplicated, i changed the table name --> problem solved