have a tree view program that i have been working with which takes data of an manual array and this i am changing so the it will read the data from a database so that i can manipulate the tree to display it as it should be
but it throws up "0x800401f0 CoInitialize has not been called. error"
***** THE load THE TREE VIEW CODE WILL GET REPLACED WITH A CALL TO THE FUNCTION BELOW THIS BUT WHEN IT RUNS IT FALL OVER AT PLACE MARKED
********* // FAILS AT THIS POINT
WHICH THROWS UP THE ERROR "0x800401f0 CoInitialize has not been called. error"
THIS IS ALL DONE IN VS2003 I HAVE REBUILT THE PROGRAM WITH MAIN AND ONE OTHER CLASS WHICH IS THE SAME CODE AS BELOW THAT FALLS OVER INTO ANOTHER PROJECT SO IT IS SIMPLY MAIN CALLING THE BELOW CODE , I BUILT THIS IN BOUT MFC FORMS AND CONSOLE AND IT WORKS FINE, SO ITS SOMeTHING TO DO WITH THE WAY THE TREEVIEW IS CONFIGURED OR IS MISSING SOMETHING
WERE DO I GO FROM HERE PLEASE
// To initialize the connection to a database using an OLE DB provider,
// two ATL classes are needed: CDataSource and CSession.
// Uses ATL's string conversion macros to convert between character encodings.
// Open the connection and initialize the data source specified by the passed
// initialization string.
// FAILS AT THIS POINT
hr = dbDataSource.OpenFromInitializationString(lpcOleConnect);
cout<<DAM<<": Unable to connect to data source "<<OLE2T(lpcOleConnect)<<endl;
hr = dbSession.Open(dbDataSource);
cout<<DAM<<": Couldn't create session on data source "<<OLE2T(lpcOleConnect)<<endl;
hr = dbDataSource.GetProperty(DBPROPSET_DATASOURCEINFO, DBPROP_DATASOURCENAME, &var);
if (FAILED(hr) || (var.vt == VT_EMPTY))
cout<<DAM<<": No Data Source Name Specified."<<endl;
cout<<DAM<<": Successfully connected to database. Data source name:\n "
// Prepare SQL query.
// LPCOLESTR query = L"SELECT ParentTable.ParentId, ParentTable.ParentName,ParentTable.a,ParentTable.b,ParentTable.c FROM ParentTable;";
// LPCOLESTR query = L"SELECT ParentTable.ParentId, ParentTable.ParentName, ChildTable.ChildId, ChildTable.ChildName FROM ParentTable INNER JOIN ChildTable ON ParentTable.ParentId = ChildTable.ParentId;";
LPCOLESTR query = L"SELECT * from bothtaables;";
cout<<DAM<<": SQL query:\n "<<OLE2T(query)<<endl;
// Excecute the query and create a record set.
hr = cmd.Open(dbSession, query);
DBORDINAL colCount = cmd.GetColumnCount();
if (SUCCEEDED(hr) && 0 < colCount)
cout<<DAM<<": Retrieve schema info for the given result set: "<<endl;
DBCOLUMNINFO* rgInfo = NULL;
OLECHAR* pStringsBuffer = NULL;
cmd.GetColumnInfo(&cColumns, &rgInfo, &pStringsBuffer);
for (int col=0; col < (int)colCount; col++)
cout<<" | "<<OLE2T(rgInfo[col].pwszName);
cout<<DAM<<": Fetch the actual data: "<<endl;
int rowCount = 0;
CRowset<CDynamicStringAccessor>* pRS = (CRowset<CDynamicStringAccessor>*)&cmd;
// Loop through the rows in the result set.
while (pRS->MoveNext() == S_OK)
// THIS IS WERE THE DATA IS DRAWN OUT OF THE TABLE AND EXPORTED OUT
for (int col=1; col <= (int)colCount; col++)
CHAR* szValue = cmd.GetString(col);
cout<<" | "<<szValue;
cout<<DAM<<": Total Row Count: "<<rowCount<<endl;
cout<<DAM<<": Error: Number of fields in the result set is 0."<<endl;
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
-Mike Kapnisakis, Warner Bros
With your subscription - you'll gain access to our exclusive IT community of thousands of IT pros. You'll also be able to connect with highly specified Experts to get personalized solutions to your troubleshooting & research questions. It’s like crowd-sourced consulting.
We can't always guarantee that the perfect solution to your specific problem will be waiting for you. If you ask your own question - our Certified Experts will team up with you to help you get the answers you need.
Our certified Experts are CTOs, CISOs, and Technical Architects who answer questions, write articles, and produce videos on Experts Exchange. 99% of them have full time tech jobs - they volunteer their time to help other people in the technology industry learn and succeed.
We can't guarantee quick solutions - Experts Exchange isn't a help desk. We're a community of IT professionals committed to sharing knowledge. Our experts volunteer their time to help other people in the technology industry learn and succeed.