我正在使用SqL Server 2014
上msado15.dll
中的C++
与Windows Server 2016
建立动态连接,提供者为MSOLEDBSQL
。代码在我添加XSL parameter
的行处中断。我没有发现该语句或XSL file
出了什么问题。
_com_error:在集合中找不到与所请求名称或顺序相对应的项目
#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;
}