Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

OVERVIEW

This documentation contains solutions for the java connection related issues. An issue belongs to this topic, if it is related with a problem by JDBC connection to the SQL Server.

KNOWN ISSUES:

1 .  JDBC driver fails to establish secure connection

Symptom:   
JDBC driver fails to establish secure connection and the following error appeared:

... 
The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer
(SSL) encryption.
...
List of related issues:
1.1. SSL handshake failed

Environment:   
JDBC driver version 1.2

Symptom:  

There is a problem by connection with JDBC driver version 1.2 and you see SSL connection related error, like: 
SSL handshake failed: The TDS protocol stream is not valid  (in com.microsoft.sqlserver.jdbc.TDSChannel) 
Unexpected message type:18 in TDS header; expected type:4 (in com.microsoft.sqlserver.jdbc.TDSReader) 
got unexpected value in TDS response at offset:4088 (in com.microsoft.sqlserver.jdbc.TDSReader) 
com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure
connection to SQL Server by using Secure Sockets Layer (SSL) encryption
 

- ...         

Solution:

The solution is described in the following SAP Note: 
1428134 - sqljdbc driver fails to establish secure connection

TABLE OF CONTENTS

1.2. Server chose unsupported or disabled protocol: SSLv3

Symptom:
There is a problem by connection with JDBC driver and you see SSL connection related error, like:

        
Could not establish open SQL connection. Exception com.sap.sql.log.OpenSQLException: Exception of type
com.microsoft.sqlserver.jdbc.SQLServerException caught:
The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption.
Error: Server chose unsupported or disabled protocol: SSLv3... com.sap.sql.log.OpenSQLException:
Exception of type com.microsoft.sqlserver.jdbc.SQLServerException caught:
The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption.
Error: Server chose unsupported or disabled protocol: SSLv3.. com.microsoft.sqlserver.jdbc.SQLServerException:
The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption.
Error: Server chose unsupported or disabled protocol: SSLv3.
              
Solution:

The problem is most probably the disabled SSL protocol. The details are in the SAP Note:
2199062 - SSL protocol and algorithm deprecation in SAP JVM

If the error is coming during upgrade with SUM, check the JVM version of the SUM.
If you find it absolutely necessary to enable SSLv3 again, check the above note and enable the SSLv3.

 

1.3. Connection reset during SSL connection

Symptom:

There is a problem by connection with JDBC driver and you see connection reset error during SSL connection: 

     com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset 
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1352)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1339)
at com.microsoft.sqlserver.jdbc.TDSChannel.read(IOBuffer.java:1654)
at com.microsoft.sqlserver.jdbc.TDSReader.readPacket(IOBuffer.java:3694) 

and you have recently applied new JDK version or patch including security changes. 

Solution:

Check the following SAP Note for the reason and solution: 
1702456 - Errors with Microsoft JDBC drivers connecting with SSL 

Common suggestions:
Check also the following MS documentation

Description:

If the above does not help check also the following MS documentations: 
https://docs.microsoft.com/en-us/security-updates/SecurityAdvisories/2015/3042058 

2 .  Server side bug

Symptom:  
Check for server side bug, for example as it is described in the following MS documentation:
https://support.microsoft.com/hu-hu/kb/2653857
"FIX: You cannot connect to SQL Server by using JDBC Driver for SQL Server after you upgrade to JRE 6 update 29 or a later version"

Solution:

Apply the fix as it is described in the related MS documentation.

 

COMMON ANALYSIS STEPS AND SOLUTIONS:

1. Check the right JDBC driver version

Description:

 Check first the following note that you are using the right version of the JDBC driver:
1398807 - Microsoft SQL Server: JDBC driver support matrix

The important part of this note extended into a table is the following:

Driver Version JDBC File name  SQL Server Versions JDK VersionJVM VersionSAP JVM Version
Version 1.2 sqljdbc.jar SQL 2000, SQL 2005, SQL 2008, SQL 2012  up to JDK 1.4 up to JVM 1.4 SAP JVM 4
Version 2.0 sqljdbc.jar SQL 2000, SQL 2005, SQL 2008 JDK 5 JVM 1.5 SAP JVM 5
Version 2.0 sqljdbc4.jar SQL 2000, SQL 2005, SQL 2008 JDK 6 JVM 1.6 SAP JVM 6
Version 3.0  sqljdbc.jar SQL 2000, SQL 2005, SQL 2008, SQL 2012 JDK 5 JVM 1.5 SAP JVM 5
Version 3.0  sqljdbc4.jar SQL 2000, SQL 2005, SQL 2008, SQL 2012 JDK 6 JVM 1.6 SAP JVM 6
Version 4.0  sqljdbc.jar SQL 2005, SQL 2008, SQL 2012 JDK 5 JVM 1.5 SAP JVM 5
Version 4.0 sqljdbc4.jar SQL 2005, SQL 2008, SQL 2012 JDK 6 JVM 1.6 SAP JVM 6
 Version 6.0 sqljdbc.jar SQL 2005, SQL 2008, SQL2012, and SQL 2014 JDK 5 JVM 1.5 SAP JVM 5
 Version 6.0 sqljdbc4.jar SQL 2005, SQL 2008, SQL2012, and SQL 2014 JDK 6 and JDK 7 JVM 1.6 and 1.7 SAP JVM 6 and 7
 Version 6.0 sqljdbc41.jar SQL 2008, SQL2012, and SQL 2014 JDK 7 JVM 1.7 SAP JVM 7
 Version 6.0 sqljdbc42.jar SQL 2008, SQL2012, and SQL 2014 JDK 8 JVM 1.8 SAP JVM 8

The following note describes also the dependence between the Netweaver version and the JVM version:

2250903 - Supported JVM versions for versions of NetWeaver Java

Based on the Netweaver version the following dependecies are relevant:

Netweaver Version

JDBC driver

JVM

NetWeaver 7.0 - 7.11

Microsoft SQL Server 2005   JDBC Driver 1.2 (*)

1.4.x

NetWeaver 7.1 - 7.11

Microsoft SQL Server JDBC   Driver 2.0  (**)

support for JDBC 3   requires JVM 5

NetWeaver 7.20 and releases < 7.5

Microsoft SQL Server JDBC   Driver 2.0  (**)

support for JDBC 4   requires JVM 6

NetWeaver 7.5

Microsoft SQL Server JDBC   Driver 4.2 and 6.0

requires JVM 8

 (*) Available for download from SAP Service Marketplace at
http://service.sap.com/swdc
"Microsoft SQL Server 2005 JDBC Driver 1.2" contains an error (see Microsoft Knowledge Base article 945842 at http://support.microsoft.com/?kbid=945842
See also SAP Note 639702.
(**) Available for download from Microsoft download center at
http://www.microsoft.com/en-us/download/details.aspx?id=2505

Implication:

If the driver should be changed, follow the description in the following note:
1145221 - JDBC driver exchange to Microsoft JDBC Driver

 

2. Check the driver version and JDBC connection on Unix or Windows

Description:

 The following SAP KBA contains a script and java program to check the JDBC driver version and the JDBC connection to the SQL Server:

2142959 - Checking the version of JDBC driver for Microsoft SQL Server

 

3. Check the connection URL on Unix or Windows

Description:

Copy-paste the following java source into an empty jdbcConnTest.java file or download it from here.

Afterwards compile it with the proper javac compiler:

import java.sql.*;
// start the test:
// java jdbcConnTest "Connection Url" username password
// E.g.:
// java jdbcConnTest "jdbc:sqlserver://localhost:1433;databasename=HUF" username passwd 
public class jdbcConnTest {
   public static void main(String[] args) {    
      String connectionUrl = args[0];
      String userName = args[1];
      String passwd = args[2];
      Connection con = null;
      Statement stmt = null;
      ResultSet rs = null;
      try {
         System.out.println("Connecting to " + connectionUrl + " ...");
         // Establish the connection.
         Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
         con = DriverManager.getConnection(connectionUrl, userName, passwd);
         String SQL = "select @@VERSION";
         stmt = con.createStatement();
         rs = stmt.executeQuery(SQL);
         while (rs.next()) {
            System.out.println(rs.getString(1));
         }
      }
      catch (Exception e) {
         e.printStackTrace();
      }
      finally {
         if (rs != null) try { rs.close(); } catch(Exception e) {}
         if (stmt != null) try { stmt.close(); } catch(Exception e) {}
         if (con != null) try { con.close(); } catch(Exception e) {}
      }
   }
}

For the java environment use the SAP specific JVM. 
Usually this is in the following directory: 

\usr\sap\[SAPSID]\SYS\exe\jvm\[Platform]\sapjvm_x.x.xxx\sapjvm_x 

Set the JAVA_HOME temporary to this directory 
Windows: 

set JAVA_HOME=[driveletter]:\usr\sap\[SID]\SYS\exe\jvm\NTAMD64\sapjvm_x.x.xxx\sapjvm_x 

Linux (or Unix): 

export JAVA_HOME=/usr/sap/[SID]/SYS/exe/jvm/[Platform]/sapjvm_x.x.xxx/sapjvm_X 

Set also temporary the path environment variable: 
Windows: 

set path=[driveletter]:\usr\sap\[SID]\SYS\exe\jvm\NTAMD64\sapjvm_x.x.xxx\sapjvm_x\bin 

Linux (or Unix): 

export PATH=/usr/sap/[SID]/SYS/exe/jvm/[Platform]/sapjvm_x.x.xxx/sapjvm_X/bin:$PATH 

First set the CLASSPATH, which contains the path to the SQL Server JDBC driver (sqljdbc.jar or sqljdbc4.jar)

or use the argument -classpath in the javac command.

Use the javac command to compile the jdbcConnTest.java file:

Afterwards the jdbcConnTest.class file should be exist.

The test for the connection URL can be started with the following command:

java jdbcConnTest "jdbc:sqlserver://<dbserver>:<port>;databaseName=<dbname>[; if necessary further parameters]" <username> <password>

or, if you did not set the environment variable CLASSPATH the argument -cp should be given in the command too:

java -cp <classpath> jdbcConnTest "jdbc:sqlserver://<dbserver>:<port>;databaseName=<dbname>[; if necessary further parameters]" <username> <password> 
e.g.:
java -cp .;/tmp/sqljdbc.jar jdbcConnTest ...
Implication:

If the connection test fails, check the error message for the cause of the problem. Check also that the connection URL, the user name and password are correct. 

 

4. Check the JDBC Driver location

Description:

Check in the already mentioned note that the JDBC driver is in right location:
639702 - JDBC driver for Microsoft SQL Server

The important part of this note is the following:

(SAP NetWeaver'04, Java:) usr\sap\<SAP SID>\JC<InstanceNumber>\j2ee\jdbc
(SAP NetWeaver'04, ABAP+Java:) usr\sap\<SAP SID>\DVEBMGS<InstanceNumber>\j2ee\jdbc
(SAP NetWeaver 7.0 and higher:) usr\sap\<SAPSID>\SYS\exe\<NUC|UC>\Platform\mssjdbc

 

5. Check the SAP configuration of JDBC driver

Description:

Based on the following note check that the configuration property rdbms.driverLocation and the profile parameter j2ee/dbdriver
are set correctly:            
867976 - Changing JDBC driver on WEB AS Java 6.40/NW 7.0x/7.1x

Check also in the ConfigTool that the JDBC driver parameters are set correctly.
For the ClassName and Url the following note describes the recent values:
1109274 - New JDBC driver for NetWeaver 7.0 and higher

jdbc/pool/<SAP SID>/ClassName = com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc/pool/<SAP SID>/Url = jdbc:sqlserver://<dbserver>:<port>;databaseName=<dbname>[; if necessary further parameters]

The following pictures shows the important settings in the ConfigTool:

If the connection does not work, you can test different connection parameters, if you choose the No button after starting the ConfigTool:

In the Direct Login page you can test the JDBC driver and the connection parameters:

 

NOTE/KBA SEARCH

In case that the above solutions are not relevant, the following search keys are suggested for note and KBA search:

Component area: BC-DB-MSS*, BW-SYS-DB-MSS*

Search keys:
- jdbc connection

 

RELATED SAP NOTES/KBAs


SAP Note    639702  - JDBC Driver for Microsoft SQL Server
SAP Note 1145221 - JDBC driver exchange to Microsoft JDBC Driver
SAP Note 1398807 - Microsoft SQL Server: JDBC driver support matrix
SAP Note 1745895 - Available Microsoft JDBC drivers
SAP Note    867976 - Changing JDBC driver on WEB AS Java 6.40/NW 7.0x/7.1x
SAP Note 1109274 - New JDBC driver for NetWeaver 7.0 and higher
SAP Note 1433363 - Enabling SQL Server 2005 Driver v2.0 for SAP NetWeaver 7.1x
SAP Note 1449988 - MS JDBC driver 1.2 DOES support SQL Server 2008
SAP Note 1768902 - Difference in specs for JDBC3 and 4 impact SQL Server driver
SAP Note 1428134 - sqljdbc driver fails to establish secure connection

SAP KBA 2142959 - Checking the version of JDBC driver for Microsoft SQL Server

RELATED DOCUMENTS


Using the JDBC Driver: https://technet.microsoft.com/en-us/library/ms378526.aspx

Feedback

Please provide any feedback or questions regarding the content under the current page comments. If you have an issue or is looking for help, try to post your question on SAP community with Microsoft SQL Server tag.

In order to leave comments, you must be logged on with your SAP account.

  • No labels