Notes for running XML Bulkload in the. NET Environment

Source: Internet
Author: User

When importing a large amount of XML data to SQL Server, we usually use XML Bulkload. I recently encountered the following error when migrating an application written in VB to ASP. Net:
The QueryInterface of the SQLXMLBULKLOADLib. ISQLXMLBulkLoad interface fails.

The program code is as follows:

1 private void Page_Load (object sender, System. EventArgs e)
2 {
3 SQLXMLBULKLOADLib. SQLXMLBulkLoad3Class objXBL = new SQLXMLBULKLOADLib. SQLXMLBulkLoad3Class ();
4 objXBL. ConnectionString = "Provider = sqloledb; server = (local); database = Digi; uid = sa; pwd = ";
5 objXBL. ErrorLogFile = "d: \ error. log ";
6 objXBL. KeepIdentity = false;
7 objXBL. Execute ("d :\\ test. xsd", "d :\\ test. xml ");
8}

At first, I thought it was a syntax problem. After debugging, I found that Windows applications in. Net run normally. Only then can we find that it was a Thread problem. The reason why Bulkload can run normally in Windows applications of VB and. Net is that they run in a single thread by default.

So rewrite the program: 1 private void Page_Load (object sender, System. EventArgs e)
2 {
3 Thread bulkLoad = new Thread (new ThreadStart (BulkIt ));
4 bulkLoad. ApartmentState = ApartmentState. STA;
5 bulkLoad. Start ();
6}
7
8
9 public void BulkIt ()
10 {
11 SQLXMLBULKLOADLib. SQLXMLBulkLoad3Class objXBL = new SQLXMLBULKLOADLib. SQLXMLBulkLoad3Class ();
12 objXBL. ConnectionString = "Provider = sqloledb; server = (local); database = Digi; uid = sa; pwd = ";
13 objXBL. ErrorLogFile = "d: \ error. log ";
14 objXBL. KeepIdentity = false;
15 objXBL. Execute ("d :\\ test. xsd", "d :\\ test. xml ");
16}

Running properly! Of course, don't forget to add:
Using System. Threading;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.