The following code executes the same machine instruction as
OLE DB, and this will fail on non-Pentium class computers:
void main()
{
__int64 dummy;
__int64 xch;
__int64 comp;
volatile __int64* pDest = & dummy;
__asm
{
mov esi,pDest
mov eax,DWORD PTR comp[0]
mov edx,DWORD PTR comp[4]
mov ebx,DWORD PTR xch[0]
mov ecx,DWORD PTR xch[4]
_emit 0xF0
_emit 0x0F
_emit 0xC7
_emit 0x0E
}
}
When this code is run on a non-Pentium class computer, it fails on the
call to "_emit 0XF0" because non-Pentium class CPUs do not have this
instruction available.
ADO
The following ADO code produces the 0x80004005 error:
Note
You must change the uid=<username> value and the pwd=<strong password> value to
the correct values before you run this code. Make sure that uid has the
appropriate permissions to perform this operation on the database.
Dim cn As New ADODB.Connection
cn.Provider = "SQLOLEDB"
cn.ConnectionString = "SERVER=myserver;DATABASE=pubs;uid=<username>;pwd=<strong password>;"
cn.Open
C++ / OLE DB
The following C++ OLE DB code results in an E_FAIL error message
on the call to IDBInitialize->Initialize():
Note
You must change the uid=<username> value and the pwd=<strong password> value to
the correct values before you run this code. Make sure that uid has the
appropriate permissions to perform this operation on the database.
void main()
{
HRESULT hr;
CLSID clsid;
const ULONG nProps = 1;
IDBProperties * pIDBProperties = NULL;
IDataInitialize * pIDataInitialize = NULL;
DBPROP InitProperties[ nProps ];
DBPROPSET rgInitPropSet;
InitProperties[ 0 ].dwPropertyID = DBPROP_INIT_PROVIDERSTRING;
InitProperties[ 0 ].vValue.vt = VT_BSTR;
InitProperties[ 0 ].vValue.bstrVal = SysAllocString( OLESTR( "SERVER=myserver;DATABASE=pubs;uid=<username>;pwd=<strong password>;" ) );
InitProperties[ 0 ].dwOptions = DBPROPOPTIONS_REQUIRED;
InitProperties[ 0 ].colid = DB_NULLID;
InitProperties[ 0 ].dwStatus = DBPROPSTATUS_OK;
rgInitPropSet.guidPropertySet = DBPROPSET_DBINIT;
rgInitPropSet.cProperties = nProps;
rgInitPropSet.rgProperties = InitProperties;
hr = CoInitialize( NULL );
CLSIDFromProgID( L"SQLOLEDB", & clsid );
if( FAILED( CoCreateInstance(CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER,
IID_IDataInitialize, (void**)&pIDataInitialize) ) )
{
printf( "Failed to load services\n" );
return;
}
if( FAILED( hr = pIDataInitialize->CreateDBInstance(clsid, NULL, CLSCTX_INPROC_SERVER,
NULL, IID_IDBInitialize, (IUnknown**)&pIDBInitialize) ) )
{
printf( "CreateDBInstance Failed\n" );
return;
}
pIDBInitialize->QueryInterface( IID_IDBProperties,
( void ** ) & pIDBProperties );
if( FAILED( pIDBProperties->SetProperties( 1, & rgInitPropSet ) ) )
{
printf( "failed to set properties\n" );
return;
}
SysFreeString( InitProperties[ 0 ].vValue.bstrVal );
pIDBProperties->Release();
if( FAILED( hr = pIDBInitialize->Initialize() ) )
{
printf( "initialization failed\n" );
return;
}
printf( "We connected\n" );
hr = pIDBInitialize->Release();
pIDataInitialize->Release();
}