Microsoft KB Archive/294157

= PRB: Cannot Retrieve Primary Key Using ADOX Key Object Collection =

Article ID: 294157

Article Last Modified on 11/26/2003

-

APPLIES TO


 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6
 * Microsoft Data Access Components 2.5
 * Microsoft Data Access Components 2.6
 * Microsoft Data Access Components 2.7

-



This article was previously published under Q294157



SYMPTOMS
When you use an ADOX key object collection to retrieve the primary key column information of a Microsoft Access table or SQL Server table, a C++ exception may occur. Microsoft Visual Basic code may return the following error:

operation is not supported by the provider.



CAUSE
To retrieve columns used by the primary key, ADOX uses the IDBSchemaRowset::GetRowset method with DBSCHEMA_KEY_COLUMN_USAGE, which is not supported by the SQL Server OLE DB provider (SQLOLEDB) provider and is supported only by the latest version of the Jet OLE DB Provider which is installed with the latest version of the Jet Service Pack.

For additional information about how to obtain the Jet service pack, click the following article number to view the article in the Microsoft Knowledge Base:

239114 How To: Obtain the Latest Service Pack for the Microsoft Jet 4.0 Database Engine



STATUS
This behavior is by design.



Steps to Reproduce Behavior
  Paste the following code into a .cpp file and build it as a Win32 console project:

Note You must change the User ID and the password = to the correct values before you run this code. Make sure that User ID has the appropriate permissions to perform this operation on the database.
 * 1) import &quot;c:\Program Files\Common Files\System\ADO\Msadox.dll&quot; no_namespace rename(&quot;EOF&quot;, &quot;EndOfFile&quot;)
 * 2) include 

void dump_com_error(_com_error &e) { printf(&quot;Error\n&quot;); printf(&quot;\a\tCode = %08lx\n&quot;, e.Error); printf(&quot;\a\tCode meaning = %s&quot;, e.ErrorMessage); _bstr_t bstrSource(e.Source); _bstr_t bstrDescription(e.Description); printf(&quot;\a\tSource = %s\n&quot;, (LPCSTR) bstrSource); printf(&quot;\a\tDescription = %s\n&quot;, (LPCSTR) bstrDescription); }

void main {   HRESULT hr;

CoInitialize(NULL);

try{

_CatalogPtr cat, cat1; hr= cat.CreateInstance(__uuidof(Catalog));

//Test Jet. /*       hr = cat->put_ActiveConnection(_variant_t(&quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; &quot;Data Source=C:\\Program Files\\Microsoft Visual Studio\\VB98\\nwind.mdb&quot;)); */        //Test SQLOLEDB. hr = cat->put_ActiveConnection(_variant_t(&quot;Provider=SQLOLEDB.1;User ID= ; password= ;Initial Catalog=Northwind; Data Source=SQLServer1&quot;));

_TablePtr tblEmp, tblEmp1; tblEmp = cat->Tables->Item[&quot;Employees&quot;]; //Retrieve the key information. KeysPtr keys; keys = tblEmp->Keys;

_bstr_t keyName, keyColName; long keyCount = keys->Count; long keyType; _KeyPtr key;

for(int i = 0; i< keyCount; i++) {           key = keys->Item[(long)i]; keyName = key->Name; keyType = key->Type; //adKeyPrimary=1, adKeyForeign=2, adKeyUnique= 3 printf(&quot;key %d : %s type = %i \n- columns for this key: \n&quot;, i, (LPCSTR)keyName, keyType);

ColumnsPtr keyCols = key->Columns; long g = keyCols->Count;

for (int j=0; jItem[(long)i]->Name); }          }    }

catch (_com_error &e) {     dump_com_error(e); }

CoUninitialize; }                    Set a breakpoint at the call to CoUninitialize. Compile the project and do a debug run (F5). You will see following error returned in the console window:

Error Code = 800a0cb3 Code meaning = Unknown error 0x800A0CB3 Source = (null) Description = (null)



Keywords: kbnofix kbprb KB294157

-

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

© Microsoft Corporation. All rights reserved.