SqlXml MemoryStream Bulk Load Errors

Tech-Archive recommends: Speed Up your PC by fixing your registry



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

.



Relevant Pages

  • Re: MS Access Shell use to call external application with audio
    ... Thank you but this application I am calling has hundreds of audio files ... embeded in an xml file. ... Prev by Date: ...
    (comp.databases.ms-access)
  • RE: Serialization of an array
    ... My guess is your difficulty isn't so much with serialization as it is writing to and then reading from the xml file. ... >My intention is to store an array of singles inside a DataTable so that it ... > 'create memory stream and formatter ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Global.mpt
    ... It can usually be fixed by saving the project ... XML file and then reopening in Project. ...
    (microsoft.public.project)
  • Re: 8ms Timer for serial port access
    ... Then start calling readagain. ... stream of bytes that you acquire by calling read. ... Forget about timing. ... can read and be guaranteed that you have a complete frame). ...
    (comp.os.linux.development.apps)
  • Re: Re-reading a Stream without reopening
    ... I have a connection to an XML file on a site I do not control, ... a string representation of the xml data that I can then feed to my ... - but the stream is at the end and doesn't support seeking. ... newStream to populate my SFileReader object? ...
    (microsoft.public.dotnet.framework.aspnet)