I am new to Android app development and I'm trying to connect to an Azure SQL DB with the native MS JDBC driver (sqljdbc4.jar) and I keep on getting the following error:
"Error connection: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "Socket closed"."
i am able to connect to the DB with the same connectionstring with squirrel though.
i use android studio 2.1.3 and i am really at the end of my wits... here is the code:
DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String username = "<>";
String password = "<>";
java.sql.Connection DbConn = DriverManager.getConnection("jdbc:sqlserver://<myserver>:1433;databaseName=thumbsupp;user=" + username + ";password=" + password + ";encrypt=true;trustServerCertificate=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;");
i even tried to open a socket on port 1433 in code:
SocketFactory sf = SSLSocketFactory.getDefault();
SSLSocket socket = (SSLSocket) sf.createSocket("<myserver>", 1433);
HostnameVerifier hverify = HttpsURLConnection.getDefaultHostnameVerifier();
SSLSession ssoc = socket.getSession();
but to no prevail although I get true
when calling
hverify.verify();
Am I missing some configurations from Android Studio?
edit: if a check the enabled protocols on the socket:
socket.getEnabledProtocols();
the only protocols i get back are TLS1.0, TLS1.1 and TLS1.2 ??