perfectxml.com
 Basic Search  Advanced Search   
Topics Resources Free Library Software XML News About Us
home » info bank » Ask perfectxml.com Team Mon, Aug 13, 2007
How do I use SQLXML 3.0 Bulk Load in C# .NET?
SQLXML 3.0 Bulkload functionality is provided via a COM object (xblkld3.dll). This component can be used in .NET through COM-interop. You can add a reference to xblkld3.dll COM DLL (Project | Add Reference…| COM tab and select Microsoft SQLXML Bulkload 3.0 Type Library) or use tlbimp.exe to create a managed wrapper for the COM DLL that can be used from within the .NET code. The Add Reference… creates an assembly file named Interop.SQLXMLBULKLOADLib.dll, and now you can use the following code to bulk load the XML file into SQL Server:
using SQLXMLBULKLOADLib;
…
…
SQLXMLBulkLoad3Class bulkLoad = new SQLXMLBulkLoad3Class();
bulkLoad.ConnectionString = txtDBConnStr.Text;

bulkLoad.Execute(txtSchemaFile.Text, txtSourceXML.Text);
Click here to download the sample C# application that illustrates this.


SQLXML 3.0 Bulkload in C#: Download this sample application


Note that SQLXML Bulkload component will not run in a multi-threaded environment, and will produce the InvalidCastException exception "QueryInterface for interface SQLXMLBULKLOADLib.ISQLXMLBulkLoad failed.". To fix this, either use the [STAThread] attribute or write the following line:
System.Threading.Thread.CurrentThread.ApartmentState = System.Threading.ApartmentState.STA;

Related Links:
  • SQLXML Bulkload KB Articles
  • SQLXML FAQs: Bulkload
  • Using XML Bulk Load to Load ADO-Generated XML Data
  • XML Bulk Load Overview
  • SQLXML 3.0 SP1

  Contact Us |  | Site Guide | About PerfectXML | Advertise ©2004 perfectxml.com. All rights reserved. | Privacy