FIX: You may receive an error message when you load the SQL Server 2000 Driver for JDBC and the SQL Server 2005 Driver for JDBC in the same application, you try to connect to a SQL Server 2005 database, and then you run a query (915834)



The information in this article applies to:

  • Microsoft SQL Server 2000 Driver for JDBC

Bug#: 2059 (PSSWebData)

SYMPTOMS

Consider the following scenario. You load the Microsoft SQL Server 2000 Driver for JDBC in an application. Then, you load the Microsoft SQL Server 2005 JDBC Driver in the same application. In this scenario, when you try to connect to a SQL Server 2005 database by using a SQL Server 2005 JDBC Driver URL, the connection is established by using the Microsoft SQL Server 2000 Driver for JDBC. If you subsequently run a query, you receive the following error message:
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 1 (""): Data type 0x38 is unknown.
If you establish a connection to a SQL Server 2000 database, you may not receive any error message, and the fact that the wrong driver is being used may be unnoticed. You experience this problem when the SQL Server 2000 Driver for JDBC is loaded before the Microsoft SQL Server 2005 JDBC Driver is loaded in the application.

CAUSE

This problem occurs because faulty name resolution occurs in the SQL Server 2000 JDBC driver. The SQL Server 2000 JDBC driver accepts connection URLs from the SQL Server 2005 JDBC Driver. The SQL Server 2005 JDBC Driver connection string URLs start with the following string:

jdbc:sqlserver://ConnectionString

The SQL Server 2000 Driver for JDBC should only accept connection string URLs that start with the following string:

jdbc:microsoft:sqlserver://ConnectionString

However, the SQL Server 2000 Driver for JDBC also accepts connections that have the following format:

jdbc:sqlserver://ConnectionString

The exception occurs because the SQL Server 2000 Driver for JDBC is not designed to connect to a SQL Server 2005 database.

RESOLUTION

A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next SQL Server 2000 Driver for JDBC service pack that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

File information

The English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time item in Control Panel.
File nameFile sizeDateTime
Msbase.jar289,71303-Feb-200623:02
Mssqlserver.jar67,48303-Feb-200623:02
Msutil.jar56,53703-Feb-200623:02

WORKAROUND

To work around this problem, follow these steps:
  1. Load the SQL Server 2005 Driver for JDBC before you load the SQL Server 2000 Driver for JDBC. To do this, use the DriverManager class as in the following code example.
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); // 2005 version
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); // 2000 version
    
  2. Use a SQL Server 2005 Driver for JDBC connection URL to establish a connection. To do this, use code that resembles the following code example.
    Connection con = DriverManager.getConnection("jdbc:sqlserver://<ServerName>;user=<UserName>;password=<Password>");
For more information about how to connect with data sources and how to use a connection URL, visit the following Microsoft Developer Network (MSDN) Web sites:

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to reproduce the problem

Compile and then run the following Java code sample.
import java.sql.*;
public class TestDriver {
  public static void main(String[] args) throws Exception
       	{

       	Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
       	Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

	Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://<Server>;DatabaseName=<DatabaseName>", 
"<UserId>","<Passwd>");
	DatabaseMetaData dbmd = conn.getMetaData();
	System.out.println("Driver = " + dbmd.getDriverName() + "_" + dbmd.getDriverVersion());

	conn = DriverManager.getConnection("jdbc:sqlserver://<Server>;DatabaseName=<DatabaseName>", 
"<UserId>","<Passwd>");
	dbmd = conn.getMetaData();
	System.out.println("Driver = " + dbmd.getDriverName() + "_" + dbmd.getDriverVersion());
	displayVersions(conn);
	}

	public static void displayVersions(Connection conn)
       	{
               Statement s3 = null;
               ResultSet rr = null;

               try
               {
                       s3 = conn.createStatement();
                       System.out.println("\nStart trying to retreive data\n");
                       rr = s3.executeQuery("select @@version");

                       boolean OK = rr.next();
                       if (OK)
                               System.out.println("The current version of Microsoft SQL Server is: " + rr.getString(1));
                       else
                               System.out.println("result set NO ROWS!");
               }
               catch (Exception ex)
               {
                       System.out.println("Caught error in displayAnyData:\n\t" + ex.getMessage());
               }

               try
               {
                       if (rr != null) rr.close();
                       if (s3 != null) s3.close();
                       System.out.println("End trying to retreive data\n");
               }
               catch (Exception ee)
               {
                       System.out.println("Error closing rr or s3 in displayData: " + ee.getMessage());
               }

	}

	}
Note To use this code sample, replace the following placeholders:
  • Replace <Server> with the name of the instance of SQL Server.
  • Replace <DatabaseName> with the name of the database.
  • Replace <UserId> with your user ID.
  • Replace <PassWd> with your password.

REFERENCES

For more information about JDBC, click the following article number to view the article in the Microsoft Knowledge Base:

313100 How to get started with Microsoft JDBC

The third-party products that this article discusses are manufactured by companies that are independent of Microsoft. Microsoft makes no warranty, implied or otherwise, regarding the performance or reliability of these products.

Modification Type:MajorLast Reviewed:7/19/2006
Keywords:kbHotfixServer kbQFE kbfix KB915834 kbAudITPRO kbAudDeveloper