I am trying to transform the XML with the following code but this is breaking at line where adding a XSL property.
Database used is SQL Server 2014
_com_error: Item cannot be found in the collection corresponding to the requested name or ordinal
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile") int main(int argc, char* argv[]) { HRESULT hr = S_OK; try { CoInitialize(NULL); // Define string variables. _bstr_t strCnn("Provider=MSOLEDBSQL;DATABASE=Sample;Data Source=IS-DEV;Trusted_Connection=Yes;"); _ConnectionPtr mAdoConn; _CommandPtr cmd; _StreamPtr outStrm; const char *xslfile; xslfile = "C:\\script\\Test_xsl\\example-html.xsl"; _variant_t vra(DISP_E_PARAMNOTFOUND, VT_ERROR); _variant_t vtEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR); hr = mAdoConn.CreateInstance(__uuidof(Connection)); if (FAILED(hr)) { printf("Failed creating record set instancen"); return 0; } hr = mAdoConn->Open(strCnn, L"", L"", -1); // Set the Command hr = cmd.CreateInstance(__uuidof(Command)); cmd->ActiveConnection = mAdoConn; hr = cmd->put_CommandTimeout(900); _bstr_t sqlQuery = "SELECT Id,Title,Artist,Country,Company,Price,Year FROM CDCatalog CD ORDER BY Id FOR XML AUTO"; hr = cmd->put_CommandText(sqlQuery); hr = cmd->Properties->Item[L"XSL"]->put_Value(_variant_t(xslfile)); // Set-up the output stream hr = outStrm.CreateInstance(__uuidof(Stream)); hr = outStrm->Open(vtEmpty, adModeUnknown, adOpenStreamUnspecified, L"", L""); hr = cmd->Properties->Item[L"Output Stream"]->put_Value(_variant_t((IDispatch*)outStrm)); hr = cmd->Properties->Item[L"Output Encoding"]->put_Value(_variant_t("utf-8")); //ISO-8859-1")); hr = cmd->Execute(&vra, &vtEmpty, adExecuteStream); } catch (_com_error &ce) printf("Error:%s", (char *)ce.Description()); CoUninitialize(); _getch(); return 0;
↧
Transform XML to html with XSL using msado15.dll
↧