Microsoft ODBC Driver for Oracle Truncates Error Messages
ID: Q239099
|
The information in this article applies to:
-
Microsoft ODBC for Oracle (Build 2.573.4202), version 2.5
SYMPTOMS
In the Microsoft Open Database Connectivity (ODBC) Driver for Oracle, error messages greater than 255 characters are randomly truncated. The number of characters returned to the application may vary depending on the number of characters in the error message. This problem does not occur when using the ODBC driver from Oracle.
The ODBC header file Sql.h defines SQL_MAX_MESSAGE_LENGTH to be 512 characters, permitting messages of up to 511 characters, plus a Null termination character, to be returned.
CAUSE
Internal to the ODBC driver, the error message buffer is declared as a UCHAR datatype. The UCHAR type has a maximum size of 255 (0xFF) characters.
RESOLUTION
A supported fix that corrects this problem is now available from Microsoft, but
it has not been fully regression tested and should be applied only to systems
experiencing this specific problem. If you are not severely affected by this
specific problem, Microsoft recommends that you wait for the next Microsoft Data Access Components service pack
that contains this fix.
To resolve this problem immediately, contact Microsoft Product Support Services
to obtain the fix. For a complete list of Microsoft Product Support Services
phone numbers and information on support costs, please go to the following
address on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.asp
The English version of this fix should have the following file attributes or later:
Date Time Version Size File name Platform
-------------------------------------------------------------
8/3/99 2.573.4402 141KB Msorcl32.dll
NOTE: If this product was already installed on your computer when you purchased it from the Original Equipment Manufacturer (OEM) and you need this fix, please call the Pay Per Incident number listed on the above Web site. If you contact Microsoft to obtain this fix, and if it is determined that you only require the fix you requested, no fee will be charged. However, if you request additional technical support, and if your no-charge technical support period has expired, or if you are not eligible for standard no-charge technical support, you may be charged a non-refundable fee.
For more information about eligibility for no-charge technical support, see the following article in the Microsoft Knowledge Base:
Q154871
Determining If You Are Eligible for No-Charge Technical Support
STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed
at the beginning of this article.
MORE INFORMATION
Manual Installation
- Close or stop any applications or services that are using Msorcl32.dll. This may include Internet Information Server (IIS), Microsoft Transaction Server (MTS), and any ODBCDirect, ODBC, ADO, or OLE DB applications.
- Download the hotfix version of Msorcl32.dll into a temporary directory.
- Locate and rename the current version of Msorcl32.dll, which is in the \Winnt\System32 folder for Windows NT machines, and in the \Windows\System folder for Windows 9x machines.
- Copy the hotfix version of Msorcl32.dll into the same location, and then restart your services and applications.
Important Notice for Microsoft Windows 95/98 Users
If you are installing this fix onto a computer running Windows 95 or a computer with the original release of Windows 98, you may need to install the Windows 98 Migration dynamic-link library (DLL) included with this fix. Please carefully read the Migrate_qfe.txt file that is included in the Migration.exe file that is included with the download.
Steps to Reproduce
Create a new console application in Visual C++ by using the following code. This code creates a stored procedure in Oracle that deliberately raises an Oracle error, and then returns a large error message.
When the code is run, the number of characters returned in the error message is not the maximum defined size of 512 (511 plus the Null termination character).
Please note that you must modify the code to use the correct ODBC DSN, userId, and password. Also, coping and pasting this code might produce compiler errors because of lost text formatting. Correct the text formatting in a Visual C++ editor before compiling by bringing appropriate statements to new line.
#include <windows.h>
#include <stdio.h>
#include <sql.h>
#include <sqlext.h>
main()
{
RETCODE rc;
HENV henv;
HDBC hdbc;
HSTMT hstmt;
char * dsn = "YourServer";
char * uid = "scott";
char * pwd = "tiger";
char * SQLStr = "{call TESTERR}";
SQLCHAR createProc[] = "CREATE OR REPLACE PROCEDURE TESTERR AS output_err_msg VARCHAR2(1000); raised_error_string "
"VARCHAR2(2); BEGIN raised_error_string := 'This assignment will raise an exception'; EXCEPTION WHEN "
"OTHERS THEN output_err_msg :='This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"Errors!';raise_application_error(-20250, output_err_msg);END;";
// Variables for SQLGetDiagRec.
SQLCHAR sqlState[20];
SQLCHAR errorMsg[1000];
SQLSMALLINT errorMsgLen;
SQLINTEGER nativeError;
char szTemp[4096];
rc = SQLAllocEnv(&henv);
rc = SQLAllocConnect(henv, &hdbc);
rc = SQLConnect(hdbc, (unsigned char *)dsn,
SQL_NTS, (unsigned char *)uid,
SQL_NTS, (unsigned char *)pwd, SQL_NTS);
rc = SQLAllocHandle(SQL_HANDLE_STMT, hdbc,&hstmt);
// Create the stored procedure in Oracle.
rc = SQLExecDirect(hstmt, (unsigned char *)createProc, SQL_NTS);
SQLFreeStmt(hstmt, SQL_CLOSE);
// Run the newly created stored procedure.
rc = SQLExecDirect(hstmt, (unsigned char *)SQLStr, SQL_NTS);
// Retrieve the raised error message.
SQLGetDiagRec(SQL_HANDLE_STMT,hstmt,1,sqlState,
&nativeError,errorMsg,1000,&errorMsgLen);
// Display the size of the returned error message, and the message itself.
sprintf(szTemp, "Length=[%d] Text=[%s]", strlen((char*)errorMsg), errorMsg );
MessageBox(NULL, (LPSTR) szTemp,"ODBC Error Message",0);
SQLFreeStmt(hstmt, SQL_CLOSE);
SQLFreeStmt(hstmt, SQL_DROP);
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);
return(TRUE);
};
Additional query words:
oracle odbc driver truncate error messages 255 512 sql_max_message_length hotfix
Keywords : kbDatabase kbDriver kbODBC kbOracle kbGrpVCDB kbDSupport
Version : :2.5
Platform : WINDOWS
Issue type : kbbug