HOWTO: Passing a License Key to ADO in Visual C++ Using #importLast reviewed: August 17, 1998 |
The information in this article applies to:
SUMMARYThe #import directive is used to incorporate information from a type library, but makes no provision for a license key. If you installed the OLE- DB SDK or Internet Information Server 3.0, then the license key is automatically created in the registry. If your application, though, is redistributed to machines that have not had either OLE-DB SDK or Internet Information Server 3.0 installed on them, you need to programatically provide the ADO License Key. This is necessary regardless of the development environment you are using to manipulate ADO. MORE INFORMATIONA typical #import statement is as follows: #import "msado10.dll" no_namespace rename( "EOF", "adoEOF" ) When using #import to generate classes for ADO, your code to manipulate a recordset might look like this: HRESULT hr; _ConnectionPtr pConn; _bstr_t bstrConnect = SysAllocString( L"driver={sql server};" L"Database=pubs;" L"UID=sa;PWD=;" ); hr = pConn.CreateInstance(__uuidof(Connection)); if (!FAILED(hr)) pConn->ConnectionString = bstrConnect; This works on any machine that has had the ADO 1.0 License Key already installed. However, if the license key is not installed, this code does not work. The code sample below is functionally equivalent but demonstrates how to create an ADO object using a license key: BSTR LicKey; IClassFactory2 *pIUnknown = NULL; IUnknown *pOuter = NULL; HRESULT hr; _ConnectionPtr pConn; _bstr_t bstrConnect = SysAllocString( L"driver={sql server};" L"Database=pubs;" L"UID=sa;PWD=;" ); LicKey = SysAllocString( L"gxwaezucfyqpwjgqbcmtsncuhwsnyhiohwxz" ); // hr = CoGetClassObject( __uuidof(Connection), CLSCTX_INPROC_SERVER, NULL, IID_IClassFactory2, reinterpret_cast<void**>(&pIUnknown) ); if( !FAILED( hr ) ) { pIUnknown->CreateInstanceLic( pOuter, NULL, __uuidof(_Connection), LicKey, reinterpret_cast<void**> (&pConn) ); } if( !FAILED( hr ) ) pConn->ConnectionString = bstrConnect; SysFreeString( LicKey ); REFERENCESThis article is one of a series dealing with the redistribution of Microsoft Data Access Components (MDAC); ODBC, OLE DB, ADO, RDS, the MDAC Standalone, MDAC Redistribution and the Data Access SDK. The whitepaper "Redistributing Microsoft Data Access Components" presents a comprehensive overview of this subject, including referencing the content of this Knowledge Base article. This whitepaper is located at the following Web address: http://www.microsoft.com/msdn/news/feature/datajul98/redistmdac.htm For additional information, please see the following article in the Microsoft Knowledge Base: ARTICLE-ID: Q168122 TITLE : HOWTO: Redistributing ADO 1.0 or ADO/R 1.0 with OLE/DB 1.1 Keywords : kbcode adoengdb adovc CLIss MfcDatabase Platform : WINDOWS Issue type : kbhowto |
================================================================================ |
Last reviewed: August 17, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.