Hello,
A huge problem and cant find out what it is!! Please if someone knows
what the reason is to fail initialization, help!
I grab the code of NorthWindOleDb for SQL CE 2.0 and that one works
fine. But when I use the code to develop my own application, it
crashs! The function below is a my code.
This is very urgent, please help!!
Kind regard,
Zen
Soft.Engineer.
========================
HRESULT DBApplication::OpenDatabase()
{
// Error code reporting
HRESULT hr = NOERROR;
// Property used in property set to initialize provider
DBPROP dbprop[1];
// Property Set used to initialize provider
DBPROPSET dbpropset[1];
// Provider Interface Pointers
IDBInitialize *pIDBInitialize = NULL;
IDBProperties *pIDBProperties = NULL;
VariantInit(&dbprop[0].vValue);
// Create an instance of the OLE DB Provider
hr = CoCreateInstance( CLSID_SQLSERVERCE_2_0,
0,
CLSCTX_INPROC_SERVER,
IID_IDBInitialize,
(void **) &pIDBInitialize );
if ( FAILED(hr) )
{
MessageBox(NULL,L"CoCreateInstance failed!", L"Casper", MB_OK);
goto Exit;
}
// Initialize a property with name of database
dbprop[0].dwPropertyID = DBPROP_INIT_DATASOURCE;
dbprop[0].dwOptions = DBPROPOPTIONS_REQUIRED;
dbprop[0].vValue.vt = VT_BSTR;
dbprop[0].vValue.bstrVal = SysAllocString(DATABASE_MCASPER);
if(dbprop[0].vValue.bstrVal == NULL)
{
hr = E_OUTOFMEMORY;
goto Exit;
}
// Initialize the property set
dbpropset[0].guidPropertySet = DBPROPSET_DBINIT;
dbpropset[0].rgProperties = dbprop;
dbpropset[0].cProperties = sizeof(dbprop) / sizeof(dbprop[0]);
// Set initialization properties.
hr = pIDBInitialize->QueryInterface(IID_IDBProperties, (void **)
&pIDBProperties);
if(FAILED(hr))
{
MessageBox(NULL,L"pIDBInitialize->QueryInterface failed!",
L"Casper", MB_OK);
goto Exit;
}
// Sets properties in the Data Source and initialization property
groups
// new -> hr = pIDBProperties->SetProperties( sizeof(dbprop) /
sizeof(dbprop[0]), dbpropset );
hr = pIDBProperties->SetProperties(1, dbpropset);
if(FAILED(hr))
{
MessageBox(NULL,L"pIDBProperties->SetProperties failed!",
L"Casper", MB_OK);
goto Exit;
}
// Initializes a data source object
hr = pIDBInitialize->Initialize();
/*
** CRASHS!!!! Error = E_FAIL.
**/
if(FAILED(hr))
{
switch(hr)
{
case
DB_S_ASYNCHRONOUS :
MessageBox(NULL,L"async", L"Casper", MB_OK);
break;
case DB_S_ERRORSOCCURRED :
MessageBox(NULL,L"error", L"Casper", MB_OK);
break;
case E_FAIL :
MessageBox(NULL,L"efail", L"Casper", MB_OK);
break;
case E_OUTOFMEMORY :
MessageBox(NULL,L"out of mem", L"Casper", MB_OK);
break;
case E_UNEXPECTED :
MessageBox(NULL,L"unex", L"Casper", MB_OK);
break;
case DB_E_ALREADYINITIALIZED :
MessageBox(NULL,L"already", L"Casper", MB_OK);
break;
case DB_E_CANCELED :
MessageBox(NULL,L"canc", L"Casper", MB_OK);
break;
case DB_E_ERRORSOCCURRED :
MessageBox(NULL,L"errotrs occ", L"Casper", MB_OK);
break;
case DB_SEC_E_AUTH_FAILED :
MessageBox(NULL,L"auth", L"Casper", MB_OK);
break;
}
MessageBox(NULL,L"pIDBInitialize->Initialize() failed!",
L"Casper", MB_OK);
goto Exit;
}
// Get IDBCreateSession interface
hr = pIDBInitialize->QueryInterface(IID_IDBCreateSession, (void **)
&m_pIDBCreateSession);
if (FAILED(hr))
MessageBox(NULL,L"pIDBInitialize->QueryInterface!", L"Casper",
MB_OK);
Exit:
// Clear Variant
VariantClear(&dbprop[0].vValue);
// Release interfaces
if(pIDBProperties)
pIDBProperties->Release();
if(pIDBInitialize)
pIDBInitialize->Release();
return hr;
Quote:} // DBApplication::OpenDatabase