Microsoft KB Archive/924599

= FIX: Error message when you run an SQL statement by using OLE DB Provider for DB2: &quot;SQLSTATE 22007, SQLCODE -181&quot; =

Article ID: 924599

Article Last Modified on 12/4/2007

-

APPLIES TO


 * Microsoft Host Integration Server 2004 Enterprise Edition
 * Microsoft Host Integration Server 2004 Standard Edition
 * Microsoft OLE DB Provider for DB2

-



SYMPTOMS
Consider the following scenario. You run an SQL statement by using Microsoft OLE DB Provider for DB2. The SQL statement passes a Microsoft SQL Server datetime parameter to an IBM DB2 database column. The IBM DB2 database column uses the IBM DB2 DATE data type. In this scenario, you may receive the following error message:

SQLSTATE: 22007, SQLCODE: -181

For example, the following SQL statement passes a SQL Server datetime parameter to an IBM DB2 database column. declare @var1 datetime set @var1 = '2006-09-27 00:00:00.000' SELECT COL1, COL2, COL3 FROM IBMDB2.TESTDATA.USER1.TABLE1 WHERE COL2 = @var1 In this example, this problem occurs if the COL2 column uses the IBM DB2 DATE data type.



CAUSE
At runtime, OLE DB Provider for DB2 does not know the correct IBM DB2 data type for the IBM DB2 database column to which the SQL Server datetime parameter is passed. Therefore, OLE DB Provider for DB2 includes the date information and the time information in the value that OLE DB Provider for DB2 passes to the IBM DB2 database. The time information is not valid for the IBM DB2 DATE data type. Therefore, you receive the error message that is mentioned in the &quot;Symptoms&quot; section.



Microsoft Host Integration Server 2004
A supported hotfix is now available from Microsoft. However, this hotfix is intended to correct only the problem that is described in this article. Apply this hotfix only to systems that are experiencing this specific problem. This hotfix might receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next service pack that contains this hotfix.

To resolve this problem, submit a request to Microsoft Online Customer Services to obtain the hotfix. To submit an online request to obtain the hotfix, visit the following Microsoft Web site:

http://go.microsoft.com/?linkid=6294451

Note If additional issues occur or any troubleshooting is required, you might have to create a separate service request. The usual support costs will apply to additional support questions and issues that do not qualify for this specific hotfix. To create a separate service request, visit the following Microsoft Web site:

http://support.microsoft.com/contactus/?ws=support

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.

Note Because of file dependencies, the most recent hotfix that contains these files may also contain additional files.

Microsoft OLE DB Provider for DB2 version 1.0
A supported hotfix is now available from Microsoft. However, this hotfix is intended to correct only the problem that is described in this article. Apply this hotfix only to systems that are experiencing this specific problem. This hotfix might receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next service pack that contains this hotfix.

To resolve this problem, submit a request to Microsoft Online Customer Services to obtain the hotfix. To submit an online request to obtain the hotfix, visit the following Microsoft Web site:

http://go.microsoft.com/?linkid=6294451

Note If additional issues occur or any troubleshooting is required, you might have to create a separate service request. The usual support costs will apply to additional support questions and issues that do not qualify for this specific hotfix. To create a separate service request, visit the following Microsoft Web site:

http://support.microsoft.com/contactus/?ws=support

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.

64-bit (x64) version
Note Because of file dependencies, the most recent hotfix that contains these files may also contain additional files.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.



MORE INFORMATION
This hotfix adds support for a new connection string property. By using the new connection string property, you can pass a SQL Server datetime parameter to an IBM DB2 database as the IBM DB2 DATE data type. OLE DB Provider for DB2 deletes the time information in the value of the SQL Server datetime parameter. Therefore, OLE DB Provider for DB2 passes only the date information to the IBM DB2 database.

The new connection string property has the following definition:

DateTime As Date= 

In this connection string property, you can define  as TRUE or as FALSE. If you add the DateTime As Date=TRUE statement to the connection string, OLE DB Provider for DB2 converts the SQL Server datetime parameter to the IBM DB2 DATE data type. Then, OLE DB Provider for DB2 passes the value to the IBM DB2 database.

If you add the DateTime As Date=FALSE statement to the connection string, OLE DB Provider for DB2 passes the SQL Server datetime parameter to the IBM DB2 database as you specify in the SQL statement. In this case, OLE DB Provider for DB2 passes the date information and the time information to the IBM DB2 database.

Note This behavior is the default behavior if you do not add the DateTime As Date property to the connection string.

The following connection string example shows how to use the DateTime As Date property. ; Everything after this line is an OLE DB initialization string. Provider=DB2OLEDB;Password=;Persist Security Info=True;User ID=;Initial Catalog=S105FRDM;Defer Prepare=False;Derive Parameters=False;Network Transport Library=TCP;Host CCSID=37;PC Code Page=1252;Network Address=;Network Port=446;Package Collection=DB2USER;Default Schema=DB2USER;Default Qualifier=DB2USER;DBMS Platform=DB2/AS400;Process Binary as Character=False;Connection Pooling=True;Units of Work=RUW;DateTime As Date=TRUE Important After you apply this hotfix and add the DateTime As Date=TRUE statement to the connection string, you may receive the following error message:

SQLSTATE: 22007, SQLCODE: -180

This problem occurs if the IBM DB2 database column uses the IBM DB2 TIMESTAMP data type. This problem occurs because the IBM DB2 database expects to receive the date information and the time information when a query is passed to an IBM DB2 database column that uses the IBM DB2 TIMESTAMP data type. The DateTime As Date=TRUE statement causes OLE DB Provider for DB2 to delete the time information in the value of the SQL Server datetime parameter. Therefore, the data is not valid when the query is passed to the IBM DB2 database column that uses the IBM DB2 TIMESTAMP data type.

If you must query an IBM DB2 table that uses the IBM DB2 DATE data type and the IBM DB2 TIMESTAMP data type, you may have to use multiple connection strings that are configured to use the correct properties. Then, you can successfully query the various IBM DB2 data types.

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

824684 Description of the standard terminology that is used to describe Microsoft software updates

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

Keywords: kbbug kbfix kbqfe kbpubtypekc kbhotfixserver kbhis2004 kbdb2oledb KB924599

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.