SqlXml MemoryStream Bulk Load Errors
- From: "LvBohemian" <LvBohemian@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 31 May 2005 16:09:28 -0700
//I get this error:
...Argument '1': cannot convert from 'System.IO.MemoryStream' to
'SomeDll.SomeClass.MemoryStream'
//when calling this method
private void btnBulkSqlLoad_Click(object sender, System.EventArgs e)
{
int intReturn = 0;
FileStream fs = new FileStream(@"C:\XMLData\LogDetails.xml",
FileMode.Open);
MemoryStream ms = new MemoryStream(System.Convert.ToInt32(fs.Length));
StreamWriter sw = new StreamWriter( ms, new UTF8Encoding());
sw.Write( fs );
sw.Flush();
SomeDll.SomeClass obj = new SomeDll.SomeClass()
intReturn = obj.DoBulkInsert(ms);
}
//which calls this method
public void DoBulkInsert(System.IO.MemoryStream pMs)
{
SqlXmlMemoryStream = pMs;
Thread bulkLoad = new Thread( new ThreadStart( LoadData ) );
bulkLoad.ApartmentState = ApartmentState.STA;
bulkLoad.Start();
}
// Load data
public void LoadData()
{
string strConnection =
ConfigurationSettings.AppSettings["SqlXmlCon"];
string strSchema = ConfigurationSettings.AppSettings["Xdr"];
string strErrorFile = ConfigurationSettings.AppSettings["SqlXmlErr"];
try
{
string schemaName = strSchema;
int i = System.Convert.ToInt32(SqlXmlMemoryStream.Length);
byte[] dataBytes = new byte[i];
SqlXmlMemoryStream.Position = 0;
UCOMIStream dataStream;
CreateStreamOnHGlobal( 0, true, out dataStream );
int count = SqlXmlMemoryStream.Read(dataBytes, 0, i);
dataStream.Write(dataBytes, count, System.IntPtr.Zero);
dataStream.SetSize( i );
SQLXMLBULKLOADLib.SQLXMLBulkLoad3Class objBL = new
SQLXMLBULKLOADLib.SQLXMLBulkLoad3Class();
objBL.XMLFragment = true;
objBL.ConnectionString = strConnection;
objBL.ErrorLogFile = strErrorFile;
objBL.KeepIdentity = false;
objBL.Execute(schemaName, dataStream);
}
//Catch all SQL XML Bulk Load API Exceptions
catch (SqlXmlException SqlXmlEx)
{
//omitted...
}
//Catch all COM Exceptions
catch(COMException ComEx)
{
//omitted...
}
//Catch all other Exceptions
catch (Exception Ex)
{
//omitted...
}
finally
{
//omitted...
}
}
//property used by method
private MemoryStream m_MemoryStream;
public MemoryStream SqlXmlMemoryStream
{
get
{
return m_MemoryStream;
}
set
{
m_MemoryStream = value;
}
}
//Calling LoadData directly and using a xml file instead of a stream works
fine...
//Comments, suggestions?
//thanks in advance.
.
- Follow-Ups:
- Re: SqlXml MemoryStream Bulk Load Errors
- From: Bertan ARI [MSFT]
- Re: SqlXml MemoryStream Bulk Load Errors
- Prev by Date: what would the mapping file for these look like?
- Next by Date: what would be the xsd mapping file file for this XML to sql serve
- Previous by thread: what would the mapping file for these look like?
- Next by thread: Re: SqlXml MemoryStream Bulk Load Errors
- Index(es):
Relevant Pages
|