Updategram with ADO and C++...parse error

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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"
.



Relevant Pages

  • Displaying XML Stream on ASP.NET Page
    ... I am able to make HTTP request and retrieve the xml ... stream in XML Text Reader. ... Web Server control also read from XML Text Reader. ... options can I use to display stream of XML Data on ASP.NET Page. ...
    (microsoft.public.dotnet.xml)
  • Re: How to extract an entire table into an XML file?
    ... Books Online has a full section on how to get XML from the database. ... FOR XML in SQL Server 2000 returns a stream and thus should only be used ... > but the XML data returned seems to be constrained to a single record?? ...
    (microsoft.public.sqlserver.xml)
  • XML Control
    ... I am writing an application which will get stream of XML Data from a ... I am able to make HTTP request and retrieve the xml ... stream in XML Text Reader. ... Web Server control also read from XML Text Reader. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Data table text I/O package?
    ... regular and homogenuous data in mind. ... Given a data format much like in, ... I said XML is good for parsing of data if you cannot tell in advance that the data stream is totally free of errors. ... However, if some data item contains a separator due to an error, you loose the whole stream, or use the wrong data without noticing this, in the worst case. ...
    (comp.lang.ada)
  • RE: Unparsed Interchange
    ... but have you tried setting your stream position back ... from the received one (flat recieved -> xml out with some new parameters). ... // Get the original filename ... string filename = inmsg.Context.Read("ReceivedFileName", ...
    (microsoft.public.biztalk.general)