Re: SqlXml MemoryStream Bulk Load Errors



I don't think I understand the error properly.I guess you are getting a
build error.

>From code, I see that you are hitting the issue that you need to create a
special stream that will implement COM IStream interface. Here is an article
on it:
http://msdn.microsoft.com/xml/default.aspx?pull=/library/en-us/dnsql90/html/exchsqlxml.asp

It explains how to create a wrappper Stream that will make Bulkload work
..Net.


"LvBohemian" <LvBohemian@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:45ADCDD6-FB8E-44D9-A818-1C899A6E82FA@xxxxxxxxxxxxxxxx
> //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: Exception Names
    ... Tom Anderson wrote: ... One would venture to say that one nearly always reaches the end of a stream, ... Generally I see little rhyme or reason as to why some occurrences in Java are handled with return values and others with exceptions. ... For example, there's nothing exceptional about not finding a file or trying to write to a read-only file, and yet we've got FileNotFoundException. ...
    (comp.lang.java.programmer)
  • Re: Exception Names
    ... One would venture to say that one nearly always reaches the end of a stream, ... Generally I see little rhyme or reason as to why some occurrences in Java are handled with return values and others with exceptions. ...
    (comp.lang.java.programmer)
  • Re: Exceptions and Streams
    ... exceptions:: with GNAT, but I'm afraid I can't remember what. ... with 'gnatbind -E', GNAT keeps a traceback in the ... You might find it easier to create a stream which could extend itself ...
    (comp.lang.ada)
  • Re: Exception Names
    ... -1 at the end of a stream. ... It may bee goofy but it is very likely to be a whole lot faster. ... for (char c: stream) ... You have to wrap the exceptions with RuntimeExceptions. ...
    (comp.lang.java.programmer)