|
Home > Archive > MS SQL XML > May 2005 > SQLXML COMException 0xC00CEE3A
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
SQLXML COMException 0xC00CEE3A
|
|
| LvBohemian 2005-05-24, 8:24 pm |
| Here my error:
COMException: System.Runtime.InteropServices.COMException (0xC00CEE3A): A
document must contain exactly one root element.
here's my applicable test code:
public void DoBulkInsert()
{
Thread bulkLoad = new Thread( new ThreadStart( this.LoadData ) );
bulkLoad.ApartmentState = ApartmentState.STA;
bulkLoad.Start();
}
public void LoadData()
{
try
{
string schemaName = @"C:\LogDetails.xdr";
byte[] dataBytes = new byte[1000];
FileStream fs = new FileStream(@"C:\LogDetails.xml", FileMode.Open);
int i = System.Convert.ToInt32(fs.Length);
fs.Position = 0;
// declare the stream to use
UCOMIStream dataStream;
// Create the stream (with no initial memory allocated)
CreateStreamOnHGloba
l( 0, true, out dataStream );
int count = fs.Read(dataBytes, 0, i);
dataStream.Write(dataBytes, count, System.IntPtr.Zero);
dataStream.SetSize( i );
SQLXMLBULKLOADLib. SQLXMLBulkLoad3Class
objBL = new
SQLXMLBULKLOADLib. SQLXMLBulkLoad3Class
();
objBL.ConnectionString = " Provider=sqloledb;us
er
id=username;password
=password;initial catalog=dbname;data
source=servername;Co
nnect Timeout=120";
objBL.ErrorLogFile = @"C:\SqlXml.err";
// Set keep identity to false, this will let the database handle the
identity inserts...
objBL.KeepIdentity = false;
objBL.Execute(schemaName, dataStream);
}
catch (SqlXmlException SqlXmlEx)
{
SqlXmlEx.ErrorStream.Position = 0;
StreamReader srErrReader = new StreamReader(SqlXmlE
x.ErrorStream);
string strErr = srErrReader.ReadToEnd();
srErrReader.Close();
LogError("SqlXmlException: " + strErr.ToString(),1);
throw new Exception (strErr);
}
catch(COMException ComEx)
{
LogError("COMException: " + ComEx.ToString(),1);
}
catch (Exception Ex)
{
LogError("Unknown Error :" + Ex.ToString(),1);
}
}
(LogError is just an event log method I have not included for Brevity)
My Schema:
<Schema xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes"
xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<ElementType name="LogDetails" sql:relation="LogDetail">
<AttributeType name="ID" required="yes" dt:type="int"/>
<AttributeType name="EvDte" required="no" dt:type="string"/>
<AttributeType name="EvTyp" required="no" dt:type="string"/>
<AttributeType name="EvDesc" required="no" dt:type="string"/>
<AttributeType name="EvCar" required="no" dt:type="string"/>
<AttributeType name="ApNo" required="no" dt:type="string"/>
<attribute type="ID"/>
<attribute type="EvDte"/>
<attribute type="EvtTyp"/>
<attribute type="EvDesc"/>
<attribute type="EvCar"/>
<attribute type="ApNo"/>
</ElementType>
</Schema>
My File I am streaming:
<?xml version="1.0" encoding="utf-8" ?>
<LogDetail>
<LogDetails ID="999999998" EvDte="5/20/2005 3:48:45 PM" EvTyp="TEVT"
EvDesc="TED" EvCar="9998" ApNo="999-999999998"/>
<LogDetails ID="999999999" EvDte="5/20/2005 3:48:46 PM" EvTyp="TEVT"
EvDesc="TED" EvCar="9999" ApNo="999-999999999"/>
</LogDetail>
Comments, suggestions?
Thanks in advance.
| |
| Monica Frintu [MSFT] 2005-05-24, 8:24 pm |
| Hi,
You need to set the XmlFragment property to True:
objBL.XmlFragment = true;
I hope this helps.
Best regards,
Monica Frintu
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm" .
| |
| LvBohemian 2005-05-25, 3:23 am |
| that was it!
thanks a bunch!
|
|
|
|
|