PRB: DataLink Type Library Moved From MSDASC.DLL To OLEDB32.DLL In ADO 2.1

ID: Q225132


The information in this article applies to:


SYMPTOMS

An attempt to #import Msdasc.dll to gain access to the DataLink COM object and OLE DB connection dialog results in the following compiler error in Visual C++:

fatal error C1083: Cannot open type library file: 'C:\Program Files\Common Files\System\OLE DB\msdasc.dll': Error loading type library/DLL.
The same #import of Msdasc.dll worked properly in ADO 2.0 but does not work in ADO version 2.1.


CAUSE

The type library for the DataLink COM object is no longer in Msdasc.dll. The type library has been moved into Oledb32.dll.


RESOLUTION

Change Msdasc.dll to oledb32.dll in your #import statement.


STATUS

This behavior is by design.


MORE INFORMATION

Steps to Reproduce Behavior

The following code sample demonstrates how to use the DataLink COM object in Visual C++ using the #import directive.

  1. Create a blank console project and insert a new .cpp file named Main.cpp


  2. Insert the code below.


  3. Switch the #import of Msdasc.dll with Oledb32.dll in order to use the DataLink COM object with ADO 2.1.





   #include "stdio.h"
   #include "conio.h"

   // #import ADO.
   #undef EOF
   #import "c:\program files\common files\system\ado\msado15.dll"\<BR/>
no_namespace

   // In ADO 2.0, you would use the following #import statement.
   #import "c:\program files\common files\system\ole db\msdasc.dll"\ no_namespace

    // Copy and paste of this code might result in escape sequence error
  //during compile time. You can either write the whole #import statement 
//in one line, or make sure that there is no space after escape sequence                                              

//"\".   
   
   // In ADO 2.1 use the following #import statement.
   //#import "c:\program files\common files\system\ole db\oledb32.dll" \ 
   //  no_namespace

   void main() 
   {
     HRESULT hr;
     IDataSourceLocatorPtr dlPrompt = NULL;
     _ConnectionPtr conn = NULL;
     _RecordsetPtr rs = NULL;

     // Initialize COM
     ::CoInitialize( NULL );

     try
     {
       // Instantiate DataLinks object.
       hr = dlPrompt.CreateInstance( __uuidof( DataLinks ) );
       if ( FAILED( hr ) ) throw( _com_error( hr, NULL ) );

       // Prompt for connection information.
       conn = dlPrompt->PromptNew();

       // If connection object is NULL, user cancelled.
       if ( NULL == conn ) goto Exit;

       // Open connection (connection returned by DataLinks is just
       // a holder for the returned ConnectionString).
       conn->Open( conn->ConnectionString, L"", L"", -1 ); 

       // Get a list of tables and dump list to console.
       rs = conn->OpenSchema( adSchemaTables );
       printf( "Listing tables:\n" );
       while ( !rs->EOF )
       {
         printf( "%s\n", 
             (char*) (_bstr_t) 
             rs->Fields->Item[L"TABLE_NAME"]->Value );
         rs->MoveNext();
       }
     }
     catch ( _com_error &ce )
     {
       // Trace COM error information.
       printf( "\nCom Exception Information\n" );
       printf( "Description : %s\n",   (char*) ce.Description()  );
       printf( "Message     : %s\n",   (char*) ce.ErrorMessage() );
       printf( "HResult     : 0x%08x\n", ce.Error() );
     }
   Exit:
     printf( "DataLink test complete. Press any key to exit test.\n" );
     _getch();
   } 

NOTE: ADO 2.1 is available with MDAC 2.1, whereas ADO 2.0 is shipped with MDAC 2.0.

Additional query words: prompt oledb user connection dialog


Keywords          : kbADO210 kbDatabase kbGrpVCDB 
Version           : WINDOWS:2.1
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: April 16, 1999