Java7 sqljdbc4 - SQL error 08S01 on getConnection ()

I am trying to write a really simple graphical application for inserting some records into a database and reading some records (nothing unusual, just 1 table with 3 rows, no relationship). A source...

package EntryProg; import java.sql.*; import com.microsoft.sqlserver.jdbc.*; public class CourseDataEntryHandler { private Connection connect; private CallableStatement callState; private ResultSet rSet; private SQLServerDataSource dSource; public CourseDataEntryHandler() { rSet = null; callState = null; dSource = new SQLServerDataSource(); dSource.setUser(REDACTED); dSource.setPassword(REDACTED); dSource.setServerName(REDACTED); dSource.setPortNumber(REDACTED); dSource.setDatabaseName(REDACTED); dSource.setEncrypt(true); dSource.setTrustServerCertificate(true); try { 

Error here

  connect = dSource.getConnection(); 

mistake of the end

  } catch (SQLServerException e) { //TODO Figure out how to handle -- logging for now, console do { System.out.println(e.getErrorCode()); System.out.println(e.getMessage()); System.out.println(e.getSQLState()); e = (SQLServerException) e.getNextException(); } while (e != null); System.out.println("END"); System.out.println(); } } 

I get the following error ...

(code) 0

(message) SQL Server did not respond. The connection was closed.

(condition) 08S01

I verified that the username, password, server name, port and database name are accurate. If I change the username to invalid, I get the error "failed to log in", so I know that Iโ€™m pushing the server.

I was not able to fully connect once, so I know that this is not a โ€œtoo many connectionsโ€ problem, since the only person who is currently registered on the server is me through sql management studio. It does not work when I exit this, so there is definitely no problem with the connections.

The application user also has datareader / datawriter permissions. (I use Eclipse if that matters. And reference the sqljdbc4.jar library).

I donโ€™t understand where to go to fix this problem. Any help would be greatly appreciated.

EDIT Update. I also tried the connection string and used DriverManager.getConnection (connString) to establish a connection that also does not work. The result is the same. In addition, SQL Server 2008 r2 is the version of SQL Server that I use.

EDIT I โ€‹โ€‹wrote a quick C # program to test the connection, I am sure that the connection works fine in .net, unfortunately, I have to use java for this project (this is a project that I chose for myself for the class, only this requirement in Java ... the teacher does not know what is happening).

+8
java sql-server-2008 sqljdbc
source share
2 answers

Comment out the line with setEncrypt(true) :

 ... dSource.setDatabaseName(REDACTED); //dSource.setEncrypt(true); dSource.setTrustServerCertificate(true); ... 

You may have problems setting up encryption. From the setEncrypt (...) document:

When the encrypt property is set to true , the Microsoft SQL Server JDBC driver uses the default JVM security provider JSSM to negotiate SSL encryption with SQL Server. The default security provider may not support all the features necessary for successfully negotiating SSL encryption. For example, the default security provider may not support the RSA public key size used in the SQL Server SSL certificate. In this case, the default security provider may cause an error that causes the JDBC driver to terminate the connection. To resolve this issue, do one of the following:

  • Configure SQL Server with a server certificate that has a more public RSA public key

  • Configure the JVM to use a different JSSE security provider in the security properties file "/lib/security/java.security"

  • Use a different JVM

Update

With Java versions 1.6.0_29 and 7.0.0_1, Oracle introduced a security patch for the SSL / TLS BEAST attack, which is likely to cause the same problem. The above security patch is known to cause problems connecting to the MSSQL Server database with jTDS driver and Microsoft driver. You can either

  • decide not to use encryption without using setEncrypt(true) (as above)
  • or, if this is enforced by the MSSQL server, you can disable the Java patch in your JVM by setting the system property -Djsse.enableCBCProtection=false . Be careful, this will affect all SSL connections within the same virtual machine.
+14
source share

Sometimes the configuration of the engine is changed so that it does not accept external connections. After some research, the following worked for me:

  • Open SQL Server Configuration Manager
  • Get SQL Server Network Configuration
  • MSSQLSERVER Protocols (Double Click)
  • View TCP / IP (must be enabled) (Open)
  • Go to the IP Addresses tab
  • Enter in the "TCP port": 1433
  • Allowed and activated parameters must be enabled: Yes
  • Restart service
0
source share

All Articles