Large-volume data import in C #

Source: Internet
Author: User

Database db =databasefactory.createdatabase (); using(SqlConnection connection =(SqlConnection) db. CreateConnection ()) {Try{connection.                        Open (); stringTableName ="bg_payment_details"; using(SqlBulkCopy bulk =NewSqlBulkCopy (Connection, sqlbulkcopyoptions.keepidentity,NULL) {DestinationTableName=TableName, BatchSize=10000                        })                        {                            foreach(DataColumn DCinchdspayment.tables[1]. Columns) {bulk. Columnmappings.add (DC. ColumnName, DC.                            ColumnName); } bulk. WriteToServer (dspayment.tables[1]); Bulk.                        Close (); }                    }                    Catch(Exception exp) {Throwexp; }                    finally{connection.                    Close (); }                }
View Code

Code as above, is actually relatively simple, is the local assignment of a good table, and then corresponding to the target table on the server, directly using the above program is OK.

DataTable directly to the server's table.

But there is also a pit over there, and a service must be opened on both sides.

Refer to the following page

http://www.lmwlove.com/ac/ID1144

Network access to the Distributed transaction Manager (MSDTC) is disabled in Win7. Use the Component Services Administration tool to enable DTC for network access in the MSDTC security configuration. "

Because the TransactionScope object was used in the program, the test reported that network access to the Distributed transaction Manager (MSDTC) was disabled. Use the Component Services Administration tool to enable DTC for network access in the MSDTC security configuration . "The error, I am the Win7 system, the solution is as follows:
Open Control Panel-> Administrative Tools-> Component Services such as:

Then double-click Computer-> My Computer-> Distributed Transaction Coordinator, then right-click Local DTC, select the Properties option, and set the following on the Security tab:

Large-volume data import in C #

Related Article

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.