Article ID: 812554
Article Last Modified on 10/11/2005
APPLIES TO
- Microsoft Data Access Components 2.7 Service Pack 1
- Microsoft Data Access Components 2.7
- Microsoft Data Access Components 2.6 Service Pack 2
SYMPTOMS
When an application that uses the Microsoft ODBC Driver for SQL Server (Sqlsrv32.dll) to insert a double value, and that value is stored in a SQL Server table as a numeric field, the ODBC driver may insert incorrect values. The ODBC Driver for SQL Server incorrectly rounds the numeric value while converting that value from a double value.
CAUSE
This only occurs when the value of the numeric field falls in a certain range. For example, if an application inserts a numeric field value of 5,000,000,000.000000 (with a precision of 22 and scale of 6) as a double value, the ODBC Driver for SQL Server inserts the value as 5,000,000,000.000001.
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 MDAC 2.7 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.
The English version of this fix has the file attributes (or later) 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 tool in Control Panel.
Hotfix file versions for MDAC 2.7 Service Pack 1 (SP1)
Date Time Version Size File name ---------------------------------------------------------- 06-Mar-2003 19:49 2000.81.9031.35 24,576 Odbcbcp.dll 06-Mar-2003 19:49 2000.81.9031.35 380,928 Sqlsrv32.dll
Hotfix file versions for MDAC 2.7 Refresh
Date Time Version Size File name ---------------------------------------------------------- 14-Apr-2003 18:01 2000.81.9001.25 24,576 Odbcbcp.dll 14-Apr-2003 18:00 2000.81.9001.25 356,352 Sqlsrv32.dll
Hotfix file versions for MDAC 2.6 Service Pack 2 (SP2)
Date Time Version Size File name -------------------------------------------------------- 15-Mar-2003 03:18 2000.80.739.0 29,252 Odbcbcp.dll 15-Mar-2003 03:01 2000.80.739.0 455,236 Sqlsrv32.dll
STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
Steps to reproduce the problem
Run the following SQL statements in SQL Query Analyzer:
USE Northwind CREATE TABLE NumericTestTbl(fldNum numeric(22,6)) GO
- In Visual Studio .NET, create a new Visual C++ Win 32 Project (console application).
- Create a new C++ source file. To do this, follow these steps:
- On the File menu, point to New, and then click File.
- In the New File dialog box, click Visual C++ under Categories, and then click C++ File (.cpp) under Templates.
Paste the following code in the file:
// The include files #include <windows.h> // For windows apps. #include <sql.h> // ODBC Core Functions #include <sqlext.h> // Microsoft SQL Extensions #include <stdio.h> // For printf(...) #include <conio.h> // For getch() // MACROs #define CHECK_SQLRETURN(nstatus, msgStr) if (nstatus != SQL_SUCCESS && nstatus != SQL_SUCCESS_WITH_INFO) { printf(msgStr); return; } // // The main function // void main(int argc, char* argv[]) { SQLHENV henv; SQLHDBC hdbc; SQLHSTMT hstmt; SQLRETURN nstatus; SQLINTEGER ilen = 0; double dOutoutData = 0; printf("Converting Numeric to Double.\n"); printf("==========================\n"); // Allocate the Environment Handle nstatus = SQLAllocHandle(SQL_HANDLE_ENV,NULL,&henv); CHECK_SQLRETURN(nstatus, "Unable to Allocate the Environment Handle.\n") // Set the ODBC Version Environment Attribute nstatus = SQLSetEnvAttr(henv,SQL_ATTR_ODBC_VERSION,(SQLPOINTER) SQL_OV_ODBC3,0); CHECK_SQLRETURN(nstatus, "Unable to Set the ODBC Version Environment Attribute.\n") // Allocate the Connection Handle nstatus = SQLAllocHandle(SQL_HANDLE_DBC,henv,&hdbc); CHECK_SQLRETURN(nstatus, "Unable to Allocate the Connection Handle.\n") // Connect to SQL Server nstatus = SQLDriverConnect(hdbc, NULL, (SQLCHAR*) "Driver=SQL Server;Trusted Connection=Yes;Server=<My_SQL_Server>;", SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT); CHECK_SQLRETURN(nstatus, "Unable to Connect to SQL Server.\n") // Allocate the Statement Handle nstatus = SQLAllocHandle(SQL_HANDLE_STMT,hdbc,&hstmt); CHECK_SQLRETURN(nstatus, "Unable to Allocate a Statement Handle.\n") // Prepare the INSERT statement nstatus = SQLPrepare(hstmt,(SQLCHAR*) "INSERT INTO Northwind..NumericTestTbl (fldNum) VALUES(?)", SQL_NTS); CHECK_SQLRETURN(nstatus, "Unable to Prepare the INSERT statement.\n") // Bind the Parameter dOutoutData = 5000000000.000000; nstatus = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_NUMERIC, 22, 6, (SQLPOINTER) &dOutoutData, 0, &ilen); CHECK_SQLRETURN(nstatus, "Unable to Bind the Parameter.\n") // Insert the data nstatus = SQLExecute(hstmt); CHECK_SQLRETURN(nstatus, "Unable to Insert the data.\n") printf("Inserted: Record - '%lf'\n",dOutoutData); // Free the statement nstatus = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_SQLRETURN(nstatus, "Unable to Free the Statement.\n") // Prepare the SELECT statement nstatus = SQLPrepare(hstmt, (SQLCHAR *)"SELECT * from Northwind..NumericTestTbl", SQL_NTS); CHECK_SQLRETURN(nstatus, "Unable to Prepare the SELECT statement.\n") // Execute a SELECT Statement nstatus = SQLExecute(hstmt); CHECK_SQLRETURN(nstatus, "Unable to Execute a SELECT Statement.\n") // Fetch the data nstatus = SQLFetch(hstmt); CHECK_SQLRETURN(nstatus, "Unable to Fetch the data.\n") // Get Record 1 nstatus = SQLGetData(hstmt, 1, SQL_C_DOUBLE, &dOutoutData, sizeof(dOutoutData), &ilen); CHECK_SQLRETURN(nstatus, "Unable to Get Record 1.\n") printf("Retrieved: Record - '%lf'\n",dOutoutData); // Free the Statement nstatus = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_SQLRETURN(nstatus, "Unable to Free the Statement.\n") // Exit printf("Press any key to Exit:"); getch(); }
- Compile and run the application.
Change <My_SQL_Server> to the name of your SQL Server.
You see the following output:Converting Numeric to Double. ========================== Inserted: Record - '5000000000.000000' Retrieved: Record - '5000000000.000001' Press any key to Exit:
After you install the hotfix, you see the following output:
Converting Numeric to Double. ========================== Inserted: Record - '5000000000.000000' Retrieved: Record - '5000000000.000000' Press any key to Exit:
Keywords: kbbug kbfix kbqfe kbhotfixserver KB812554