Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

E_FAIL initialize SQLCE using OLEDB, URGENT!! :(

115 views
Skip to first unread message

Zen

unread,
Dec 12, 2002, 5:11:15 AM12/12/02
to
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;
} // DBApplication::OpenDatabase

Kevin Boske - [MS]

unread,
Dec 12, 2002, 2:22:00 PM12/12/02
to
Hi Zen,

Your code looks good, check the following:

Make sure that your database path used in DATABASE_MCASPER is a valid
database file.

Also, check and make sure you haven't set the file attribute to read-only.


--
Kevin Boske
SQL Server CE Team
Microsoft
----------------------------------------------------------------------------
----------------------------------------
Everything you need to know about SQL Server CE:

http://www.microsoft.com/sql/ce/techinfo/default.asp
----------------------------------------------------------------------------
----------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
----------------------------------------------------------------------------
----------------------------------------

"Zen" <zeno...@hotmail.com> wrote in message
news:7cd7203b.02121...@posting.google.com...

Amy Yuan - [MS]

unread,
Dec 13, 2002, 8:16:04 PM12/13/02
to
Hi Zen,

When you get error like E_FAIL or DB_E_ERRORSOCCURRED, you can use
IErrorRecords to get minor error code. Then either get error description
from IErrorRecords or look up the minor error code in BOL to get more
details on the error.

Sample code on IErrorRecords below. To use it, right after init fails, call
PrintErrorInfo (IID_IDBInitialize, pIDBInitialize). It prints out minor
error and error description to console.

-----------
Amy Yuan

HRESULT PrintErrorInfo(REFIID riid, IUnknown *pComponent)
{
IErrorInfo * pErrorInfo = NULL;
IErrorInfo * pErrorInfoRec = NULL;
IErrorRecords * pErrorRecords = NULL;
ISupportErrorInfo * pSupportErrorInfo = NULL;
HRESULT hr = E_FAIL;
ULONG i, ulNumErrorRecs;
ERRORINFO ErrorInfo;

memset (&ErrorInfo, '\0', sizeof(ERRORINFO));

hr = pComponent->QueryInterface(IID_ISupportErrorInfo, (LPVOID FAR*)
&pSupportErrorInfo);
if (SUCCEEDED(hr))
{
hr = pSupportErrorInfo->InterfaceSupportsErrorInfo(riid);
if(hr == S_OK)
{
hr = GetErrorInfo(0, &pErrorInfo);
if (!pErrorInfo)
{
hr = pSupportErrorInfo->Release();
return (hr);
}

hr = pErrorInfo->QueryInterface(IID_IErrorRecords, (LPVOID FAR*)
&pErrorRecords);
hr = pErrorRecords->GetRecordCount(&ulNumErrorRecs);

//If no error records but we are expecting one, then fail here
if (0 == ulNumErrorRecs)
{
hr = pSupportErrorInfo->Release();
hr = pErrorRecords->Release();
return (hr);
}

for (i = 0; i < ulNumErrorRecs; i++)
{
hr = pErrorRecords->GetBasicErrorInfo(i, &ErrorInfo);

hr = pErrorRecords->GetErrorInfo(i, NULL, &pErrorInfoRec);
BSTR bstrDescriptionOfError = NULL;
BSTR bstrSourceOfError = NULL;

hr = pErrorInfoRec->GetDescription(&bstrDescriptionOfError);
hr = pErrorInfoRec->GetSource(&bstrSourceOfError);

{
wcerr << endl << L"Source: ";
if(bstrSourceOfError)
wcerr << bstrSourceOfError << endl;
else
wcerr << L"***** NO SOURCE OF ERROR *****" << endl;

wcerr << L"Description: ";
if(bstrDescriptionOfError)
wcerr << bstrDescriptionOfError << endl;
else
wcerr << L"***** NO DESCRIPTION OF ERROR *****" << endl;

wcerr << L"Minor: " << ErrorInfo.dwMinor << endl;

wcerr << L"HRESULT: 0x" << hex << ErrorInfo.hrError << endl << endl;
}

SysFreeString(bstrDescriptionOfError);
SysFreeString(bstrSourceOfError);
ReleaseAndNullInterface(pErrorInfoRec);

getch();
}

ReleaseAndNullInterface(pErrorInfo);
ReleaseAndNullInterface(pErrorRecords);
}
ReleaseAndNullInterface(pSupportErrorInfo);
}

return hr;
}

"Zen" <zeno...@hotmail.com> wrote in message
news:7cd7203b.02121...@posting.google.com...

Zen

unread,
Dec 19, 2002, 9:28:49 AM12/19/02
to
Hello MS ;).

Thanks for your answers, it helped a lot. But now I got
another issue and that is:

I dont want to use a Seek method but just a SELECT-
statement. At this moment I can do it, but how can I get
the results for example in a structure?

Thanks a lot,
Zen

>.
>

0 new messages