Microsoft KB Archive/252699: Difference between revisions
From BetaArchive Wiki
m (Text replacement - "<" to "<") |
m (Text replacement - """ to """) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 72: | Line 72: | ||
== STATUS == | == STATUS == | ||
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the | Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section. | ||
</div> | </div> | ||
Line 85: | Line 85: | ||
<li>Create a new Microsoft Visual C++ Win32 Console application.</li> | <li>Create a new Microsoft Visual C++ Win32 Console application.</li> | ||
<li><p>Copy the following code into the application:</p> | <li><p>Copy the following code into the application:</p> | ||
<pre class="codesample">#include <windows.h | <pre class="codesample">#include <windows.h> | ||
#include <sql.h | #include <sql.h> | ||
#include <sqlext.h | #include <sqlext.h> | ||
#include <tchar.h | #include <tchar.h> | ||
#include <stdlib.h | #include <stdlib.h> | ||
#include <stdio.h | #include <stdio.h> | ||
Line 103: | Line 103: | ||
if (RetCode == SQL_INVALID_HANDLE) | if (RetCode == SQL_INVALID_HANDLE) | ||
{ | { | ||
fprintf(stderr, | fprintf(stderr,"Invalid handle!\n"); | ||
return; | return; | ||
} | } | ||
Line 112: | Line 112: | ||
++iRec, | ++iRec, | ||
(SQLCHAR *)szState, | (SQLCHAR *)szState, | ||
& | &iError, | ||
(SQLCHAR *)szMessage, | (SQLCHAR *)szMessage, | ||
(SQLSMALLINT)(sizeof(szMessage) / sizeof(TCHAR)), | (SQLSMALLINT)(sizeof(szMessage) / sizeof(TCHAR)), | ||
(SQLSMALLINT *)NULL) == SQL_SUCCESS) | (SQLSMALLINT *)NULL) == SQL_SUCCESS) | ||
{ | { | ||
fprintf(stderr,TEXT( | fprintf(stderr,TEXT("[%5.5s] %s (%d)\n"),szState,szMessage,iError); | ||
} | } | ||
Line 134: | Line 134: | ||
//Not checking the return codes in some cases for clarity. | //Not checking the return codes in some cases for clarity. | ||
nstatus = SQLAllocHandle(SQL_HANDLE_ENV,NULL,& | nstatus = SQLAllocHandle(SQL_HANDLE_ENV,NULL,&henv); | ||
nstatus = SQLSetEnvAttr(henv,SQL_ATTR_ODBC_VERSION,(SQLPOINTER) SQL_OV_ODBC3,0); | nstatus = SQLSetEnvAttr(henv,SQL_ATTR_ODBC_VERSION,(SQLPOINTER) SQL_OV_ODBC3,0); | ||
nstatus = SQLAllocHandle(SQL_HANDLE_DBC,henv,& | nstatus = SQLAllocHandle(SQL_HANDLE_DBC,henv,&hdbc); | ||
nstatus = SQLDriverConnect(hdbc,NULL, | nstatus = SQLDriverConnect(hdbc,NULL, | ||
(SQLCHAR*) | (SQLCHAR*) "Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\db1.mdb", | ||
SQL_NTS, szConnect, 1024, & | SQL_NTS, szConnect, 1024, &cbConnString, SQL_DRIVER_NOPROMPT); | ||
if (nstatus != SQL_SUCCESS & | if (nstatus != SQL_SUCCESS && nstatus != SQL_SUCCESS_WITH_INFO) | ||
{ | { | ||
HandleError(hdbc,SQL_HANDLE_DBC,nstatus); | HandleError(hdbc,SQL_HANDLE_DBC,nstatus); | ||
Line 147: | Line 147: | ||
} | } | ||
nstatus = SQLAllocHandle(SQL_HANDLE_STMT,hdbc,& | nstatus = SQLAllocHandle(SQL_HANDLE_STMT,hdbc,&hstmt); | ||
nstatus = SQLExecDirect(hstmt,(SQLCHAR*) | nstatus = SQLExecDirect(hstmt,(SQLCHAR*) "CREATE TABLE DateTable (dateval datetime)",SQL_NTS); | ||
if (nstatus != SQL_SUCCESS & | if (nstatus != SQL_SUCCESS && nstatus != SQL_SUCCESS_WITH_INFO) | ||
{ | { | ||
HandleError(hstmt,SQL_HANDLE_STMT,nstatus); | HandleError(hstmt,SQL_HANDLE_STMT,nstatus); | ||
Line 157: | Line 157: | ||
TIMESTAMP_STRUCT dateVal; | TIMESTAMP_STRUCT dateVal; | ||
memset(& | memset(&dateVal,0,sizeof(TIMESTAMP_STRUCT)); | ||
dateVal.year = 1750; | dateVal.year = 1750; | ||
dateVal.month = 1; | dateVal.month = 1; | ||
Line 163: | Line 163: | ||
nstatus = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_TYPE_TIMESTAMP, SQL_TIMESTAMP, | nstatus = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_TYPE_TIMESTAMP, SQL_TIMESTAMP, | ||
0,0,(SQLPOINTER*) & | 0,0,(SQLPOINTER*) &dateVal,0,0); | ||
nstatus = SQLExecDirect(hstmt, (SQLCHAR*) | nstatus = SQLExecDirect(hstmt, (SQLCHAR*) "INSERT INTO DateTable VALUES (?)",SQL_NTS); | ||
if (nstatus != SQL_SUCCESS & | if (nstatus != SQL_SUCCESS && nstatus != SQL_SUCCESS_WITH_INFO) | ||
{ | { | ||
HandleError(hstmt,SQL_HANDLE_STMT,nstatus); | HandleError(hstmt,SQL_HANDLE_STMT,nstatus); | ||
} | } | ||
nstatus = SQLExecDirect(hstmt,(SQLCHAR*) | nstatus = SQLExecDirect(hstmt,(SQLCHAR*) "DROP TABLE DateTable",SQL_NTS); | ||
if (nstatus != SQL_SUCCESS & | if (nstatus != SQL_SUCCESS && nstatus != SQL_SUCCESS_WITH_INFO) | ||
{ | { | ||
HandleError(hstmt,SQL_HANDLE_STMT,nstatus); | HandleError(hstmt,SQL_HANDLE_STMT,nstatus); | ||
Line 183: | Line 183: | ||
nstatus = SQLFreeHandle(SQL_HANDLE_ENV,henv); | nstatus = SQLFreeHandle(SQL_HANDLE_ENV,henv); | ||
printf( | printf("Done"); | ||
} | } | ||
</pre></li> | </pre></li> |
Latest revision as of 13:52, 21 July 2020
Article ID: 252699
Article Last Modified on 1/5/2007
APPLIES TO
- Microsoft Open Database Connectivity Driver for Access 4.0
- Microsoft Data Access Components 2.1
- Microsoft Data Access Components 2.5
- Microsoft Data Access Components 2.6
This article was previously published under Q252699
SYMPTOMS
When you insert a date prior to the year 1753 by using Microsoft Access ODBC Driver, the following error message is displayed:
RESOLUTION
To resolve this problem, apply the hotfix that is described in the following Microsoft Knowledge Base article:
264081 FIX: Incorrect pre-1753 date values with Jet ODBC driver
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 Behavior
- Create a new Microsoft Access 97 or Microsoft 2000 database.
- Create a new Microsoft Visual C++ Win32 Console application.
Copy the following code into the application:
#include <windows.h> #include <sql.h> #include <sqlext.h> #include <tchar.h> #include <stdlib.h> #include <stdio.h> void HandleError(SQLHANDLE hHandle, SQLSMALLINT hType, RETCODE RetCode) { SQLSMALLINT iRec = 0; SQLINTEGER iError; TCHAR szMessage[1000]; TCHAR szState[SQL_SQLSTATE_SIZE]; if (RetCode == SQL_INVALID_HANDLE) { fprintf(stderr,"Invalid handle!\n"); return; } while (SQLGetDiagRec(hType, hHandle, ++iRec, (SQLCHAR *)szState, &iError, (SQLCHAR *)szMessage, (SQLSMALLINT)(sizeof(szMessage) / sizeof(TCHAR)), (SQLSMALLINT *)NULL) == SQL_SUCCESS) { fprintf(stderr,TEXT("[%5.5s] %s (%d)\n"),szState,szMessage,iError); } } void main(int argc, char* argv[]) { SQLHENV henv; SQLHDBC hdbc; SQLHSTMT hstmt; SQLRETURN nstatus; SQLCHAR szConnect[1024]; SQLSMALLINT cbConnString; //Not checking the return codes in some cases for clarity. nstatus = SQLAllocHandle(SQL_HANDLE_ENV,NULL,&henv); nstatus = SQLSetEnvAttr(henv,SQL_ATTR_ODBC_VERSION,(SQLPOINTER) SQL_OV_ODBC3,0); nstatus = SQLAllocHandle(SQL_HANDLE_DBC,henv,&hdbc); nstatus = SQLDriverConnect(hdbc,NULL, (SQLCHAR*) "Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\db1.mdb", SQL_NTS, szConnect, 1024, &cbConnString, SQL_DRIVER_NOPROMPT); if (nstatus != SQL_SUCCESS && nstatus != SQL_SUCCESS_WITH_INFO) { HandleError(hdbc,SQL_HANDLE_DBC,nstatus); return; } nstatus = SQLAllocHandle(SQL_HANDLE_STMT,hdbc,&hstmt); nstatus = SQLExecDirect(hstmt,(SQLCHAR*) "CREATE TABLE DateTable (dateval datetime)",SQL_NTS); if (nstatus != SQL_SUCCESS && nstatus != SQL_SUCCESS_WITH_INFO) { HandleError(hstmt,SQL_HANDLE_STMT,nstatus); return; } TIMESTAMP_STRUCT dateVal; memset(&dateVal,0,sizeof(TIMESTAMP_STRUCT)); dateVal.year = 1750; dateVal.month = 1; dateVal.day = 1; nstatus = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_TYPE_TIMESTAMP, SQL_TIMESTAMP, 0,0,(SQLPOINTER*) &dateVal,0,0); nstatus = SQLExecDirect(hstmt, (SQLCHAR*) "INSERT INTO DateTable VALUES (?)",SQL_NTS); if (nstatus != SQL_SUCCESS && nstatus != SQL_SUCCESS_WITH_INFO) { HandleError(hstmt,SQL_HANDLE_STMT,nstatus); } nstatus = SQLExecDirect(hstmt,(SQLCHAR*) "DROP TABLE DateTable",SQL_NTS); if (nstatus != SQL_SUCCESS && nstatus != SQL_SUCCESS_WITH_INFO) { HandleError(hstmt,SQL_HANDLE_STMT,nstatus); } nstatus = SQLFreeHandle(SQL_HANDLE_STMT, hstmt); nstatus = SQLDisconnect(hdbc); nstatus = SQLFreeHandle(SQL_HANDLE_DBC,hdbc); nstatus = SQLFreeHandle(SQL_HANDLE_ENV,henv); printf("Done"); }
- Change the connection string to reflect the location of your Access database.
- Compile and run the application. Observe errors.
Additional query words: datetime incorrect insert over flow 1753 1754 1800
Keywords: kbbug kbdatabase kbjet kbpending KB252699