Updategram with ADO and C++...parse error
- From: "J Hendrich" <ajwain3000@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 21 Dec 2005 13:00:02 -0800
I'm trying to use the SQLXML Updategram feature to put XML data into a SQL
Server 2000 database in conjunction with using ADO Stream objects. When I
"Execute", I receive this error:
Error Desc: MSXML3: Invalid at the top level of the document.
Error Source: Microsoft XML Extensions to SQL Server
ADO Connection Error: Native Error: 0
Error Desc: MSXML3: Invalid at the top level of the document.
Error Number: -2147217900
Error Source: Microsoft XML Extensions to SQL Server
Error SQL State: (null)
Before I show the code, please note these four things:
1. I write the XML data to the ADO Stream, then read it back out and load it
into a MSXML DOMDocument instance and it parses OK so it is not a badly
formed XML document.
2. I have these installed: SQL Server 2000 (with SP4); SQLXML 3.0, MSXML
4.0.
3. In my program I use this import for ADO: #import "ado\\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
4. I include MSXML manually, thru: #include "msxml2.h"
Here's the source code (the error occurs on the last line where Execute is
called:
m_pConn->PutConnectionString( strDefaultConnectionString );
m_pConn->Open( L"", L"", L"",
adConnectUnspecified );
// refer to "Executing an Updategram by
using ADO"
//
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sqlxml3/htm/updategram_2icv.asp
// (which is Visual Basic) for rationale
for how to accomplish this...not sure where else it
// is documented how to do this
//_variant_t varIndexByString( L"SQLXML
Version" );
//_variant_t varSQLXMLVersionValue(
L"SQLXML 3.0" );
//m_pConn->GetProperties()->GetItem(
&varIndexByString )->PutValue( varSQLXMLVersionValue );
// associate the connection with the
command
m_pCmd->PutActiveConnection( _variant_t(
(IDispatch*)m_pConn, true ) );
// set command dialect to DBGUID_MSSQLXML.
m_pCmd->PutDialect(
L"{5d531cb2-e6ed-11d2-b252-00c04f681b71}" );
// open the input stream, and write the
Interpreted Images UpdateGram content to the stream
m_pStreamIn->Open( vtSkip,
adModeUnknown, adOpenStreamUnspecified, L"", L"" );
BSTR bstrTestXML(L"<ROOT
xmlns:updg='urn:schemas-microsoft-com:xml-updategram'><updg:sync><updg:before></updg:before><updg:after><AssessedSeries
StudyInstanceUID='1' SeriesInstanceUID='1'
AssessorId='4'/></updg:after></updg:sync></ROOT>");
m_pStreamIn->WriteText( bstrTestXML,
adWriteChar );
//m_pStreamIn->WriteText(
m_bstrInterpretedImagesInputXML, adWriteChar );
m_pStreamIn->PutPosition( 0 );
//////////////////////////////////
// DO SOME CHECKS FOR DEBUGGING PURPOSES
//////////////////////////////////
#define _DO_SOME_DEBUGGING_ 1
#ifdef _DO_SOME_DEBUGGING_
int nModeEnum = m_pStreamIn->GetMode();
_bstr_t b_strCharset =
m_pStreamIn->GetCharset();
long nSize = m_pStreamIn->GetSize();
int nStateEnum = m_pStreamIn->GetState();
int nStreamTypeEnum =
m_pStreamIn->GetType();
_bstr_t b_strDebug =
m_pStreamIn->ReadText( adReadAll );
BSTR bstrDebug = b_strDebug.GetBSTR();
IXMLDOMDocument* pTempDoc =
createDOMDocument();
exec_com( id10,
pTempDoc->put_resolveExternals( VARIANT_FALSE ), "set resolve externals to
true");
exec_com( id10,
pTempDoc->put_validateOnParse( VARIANT_FALSE ), "set validae on parse to
true");
exec_com( id10, pTempDoc->loadXML(
bstrDebug, &m_varboolStatus ), "load");
if ( ( VARIANT_TRUE != m_varboolStatus )
)
{
handleParseError( id3,
m_pAssessedSeriesInputDOM, m_pXMLDOMParseErr );
}
else
{
pTempDoc->Release();
pTempDoc = NULL;
}
m_pStreamIn->PutPosition( 0 );
#endif
/////////////////////////////////////
// STOP DOING CHECKS FOR DEBUGGING
////////////////////////////////////
// set command's command stream to the
open input stream
m_pCmd->putref_CommandStream(
m_pStreamIn );
// open the output stream (will receive
the result as xml which could be used
// for such things as obtaining identity
values generated in inserts)
m_pStreamOut->Open( vtSkip,
adModeUnknown, adOpenStreamUnspecified, L"", L"" );
// set command properties for receiving
an output stream
_variant_t varIndexOutputStream(
L"Output Stream" );
m_pCmd->GetProperties()->GetItem(
&varIndexOutputStream
)->PutValue( _variant_t( (IDispatch*)m_pStreamOut, true ) );
_variant_t varIndexOutputEncoding(
L"Output Encoding" );
_variant_t varOutputEncodingValue(
L"UTF-8" );
m_pCmd->GetProperties()->GetItem(
&varIndexOutputEncoding )->PutValue( varOutputEncodingValue );
// execute the command
_variant_t varRecordsAffected;
varRecordsAffected.vt = VT_I4;
varRecordsAffected.lVal = 0;
m_pCmd->Execute( &varRecordsAffected,
NULL, adExecuteStream );
I've been trying all sorts of things to get this to work, but without
success. One note: when I look at the size of the input stream (after
writing in the data), it is slightly less than I would expect it to be...e.g.
in the example above, there are 219 characters in the XML data, which would
be 238 bytes in Unicode, but the returned size is 236...and yet, if I read
the data out of the stream and parse it with the DOMDocument instance, it
parses okay...only when Execute is called is there a problem.
Any help would be appreciated much!
-Jon
--
"When in the company of others, I shall always consider myself the lowest of
all"
.
- Prev by Date: Re: SQL2005: shred the feeds or store as XML?
- Next by Date: why the query is slower after I Used xml index in SQL Server2005£¿
- Previous by thread: Re: XSLT in SQL Server 2005
- Next by thread: why the query is slower after I Used xml index in SQL Server2005£¿
- Index(es):
Relevant Pages
|