Re: SqlXml MemoryStream Bulk Load Errors
- From: "Bertan ARI [MSFT]" <bertan@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 2 Jun 2005 04:43:16 -0700
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.
>
.
- Follow-Ups:
- Re: SqlXml MemoryStream Bulk Load Errors
- From: LvBohemian
- Re: SqlXml MemoryStream Bulk Load Errors
- References:
- SqlXml MemoryStream Bulk Load Errors
- From: LvBohemian
- SqlXml MemoryStream Bulk Load Errors
- Prev by Date: Re: what would be the xsd mapping file file for this XML to sql serve
- Next by Date: RE: OpenXML Inserting to 4 Existing Tables
- Previous by thread: SqlXml MemoryStream Bulk Load Errors
- Next by thread: Re: SqlXml MemoryStream Bulk Load Errors
- Index(es):
Relevant Pages
|