Microsoft KB Archive/314972

From BetaArchive Wiki
Knowledge Base


FIX: IColumnsInfo::GetColumnInfo() Returns S_OK with ICommandPrepare::Prepare on Nonexistent Tables

Article ID: 314972

Article Last Modified on 9/26/2005



APPLIES TO

  • Microsoft OLE DB Provider for Jet 4.0



This article was previously published under Q314972

SYMPTOMS

If your SELECT statement refers to a table name that does not exist or is not valid, OLE DB Provider for Jet 4.0 returns S_OK for the ICommandPrepare::Prepare method and the IColumnsInfo::GetColumnInfo method.

Although the Microsoft Jet engine returns an error message to the provider, the provider does not propagate the error message to the consumer.

RESOLUTION

The provider has been fixed so that IColumnsInfo::GetColumnInfo returns E_FAIL on nonexistent tables. To resolve this problem, install the latest Microsoft Jet service pack. For additional information about the latest Jet service pack, click the following article number to view the article in the Microsoft Knowledge Base:

239114 ACC2000: Updated Version of Microsoft Jet 4.0 Available in Download Center


STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. For additional information about the latest Jet service pack, click the following article number to view the article in the Microsoft Knowledge Base:

239114 ACC2000: Updated Version of Microsoft Jet 4.0 Available in Download Center


MORE INFORMATION

Use the following code to reproduce this problem:

Note You must change the code to point to your existing .mdb file.

#include <atldbcli.h>
#include <assert.h>

 void
 main()
 {
 HRESULT hr = CoInitialize( NULL );
 assert( SUCCEEDED(hr) );

 CDataSource ds;

 //Jet 4.0
 hr = ds.OpenFromInitializationString(
 OLESTR("Provider=Microsoft.Jet.OLEDB.4.0;")
 //You must change the following path to point to your database.
 OLESTR("Data Source=C:\\CPR\\CASES\\4323\\db1.mdb")
 );

 assert( SUCCEEDED(hr) );

 CSession sess;
 hr = sess.Open( ds );
 assert( SUCCEEDED(hr) );

 CCommand<CDynamicAccessor> cmd;
 hr = cmd.Create( sess, _T("SELECT * FROM nosuchtable") );
 assert( SUCCEEDED(hr) );
 hr = cmd.Prepare(); //This returns S_OK

 CComPtr<IColumnsInfo> spColumnsInfo;
 hr = cmd.m_spCommand->QueryInterface( &spColumnsInfo );
 assert( SUCCEEDED(hr) );
 ULONG cColumns;
 DBCOLUMNINFO * rgInfo;
 OLECHAR * pStringsBuffer;
 //This returns S_OK even though cColumns is 0.
 hr = spColumnsInfo->GetColumnInfo( &cColumns, &rgInfo, &pStringsBuffer );
 if (hr != E_FAIL) 
  printf("\nReturned Success but should return E_FAIL\n");
 else 
  printf("\nReturned E_FAIL. This is the correct behavior\n");
 } 
                

This code returns "Returned Success but should return E_FAIL" when you run the code. After you apply the latest Jet 4.0 service pack, this code returns "Returned E_FAIL. This is the correct behavior".


Additional query words: non-existent non-existing invalid incorrect

Keywords: kbbug kbfix kbqfe kbhotfixserver KB314972