Article ID: 170461
Article Last Modified on 6/18/2007
#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=<username>;PWD=<strong password>;" );
hr = pConn.CreateInstance(__uuidof(Connection));
if (!FAILED(hr))
pConn->ConnectionString = bstrConnect;
This will work on any machine that has had the ADO 1.0 License Key
already installed. However, if the license key is not installed, this code will
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=<username>;PWD=<strong password>;" );
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 );
Additional query words: adoengdb
Keywords: kbcompiler kbdatabase kbhowto KB170461