Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 801533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:27:22+00:00 2026-05-14T23:27:22+00:00

I am wondering how can do a mass insert and bulk copy at the

  • 0

I am wondering how can do a mass insert and bulk copy at the same time? I have 2 tables that should be affect by the bulk copy as they both depend on each other.

So I want it that if while inserting table 1 a record dies it gets rolled back and table 2 never gets updated. Also if table 1 inserts good and table 2 an update fails table 1 gets rolled back.

Can this be done with bulk copy?

Edit

I should have mentioned I am doing the bulk insert though C#.

It sort of looks like this but this is an example I been working off. So I am not sure if I have to alter it to be a stored procedure(not sure how it would look and how the C# code would look)

private static void BatchBulkCopy()
{
    // Get the DataTable 
    DataTable dtInsertRows = GetDataTable();

    using (SqlBulkCopy sbc = new SqlBulkCopy(connectionString, SqlBulkCopyOptions.KeepIdentity))
    {
        sbc.DestinationTableName = "TBL_TEST_TEST";

        // Number of records to be processed in one go
        sbc.BatchSize = 500000;

        // Map the Source Column from DataTabel to the Destination Columns in SQL Server 2005 Person Table
        // sbc.ColumnMappings.Add("ID", "ID");
        sbc.ColumnMappings.Add("NAME", "NAME");

        // Number of records after which client has to be notified about its status
        sbc.NotifyAfter = dtInsertRows.Rows.Count;

        // Event that gets fired when NotifyAfter number of records are processed.
        sbc.SqlRowsCopied += new SqlRowsCopiedEventHandler(sbc_SqlRowsCopied);

        // Finally write to server
        sbc.WriteToServer(dtInsertRows);
        sbc.Close();
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:27:23+00:00Added an answer on May 14, 2026 at 11:27 pm

    I am wondering how can do a mass
    insert and bulk copy at the same time?
    I have 2 tables that should be affect
    by the bulk copy as they both depend
    on each other. So I want it that if
    while inserting table 1 a record dies
    it gets rolled back and table 2 never
    gets updated. Also if table 1 inserts
    good and table 2 an update fails table
    1 gets rolled back. Can this be done
    with bulk copy?

    No – the whole point of SqlBulkCopy is to get data into your database as fast as possible. It will just dump the data into a single table.

    The normal use case will be to then inspect that table once it’s imported, and begin to “split up” that data and store it into whatever place it needs to go – typically through a stored procedure (since the data already is on the server, and you want to distribute it to other tables – you don’t want to pull all that data back down to the client, inspect it, and then send it back to the server one more time).

    SqlBulkCopy only grabs a bunch of data and drops it into a table – very quickly so. It cannot split up data into multiple tables based on criteria or conditions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering if people can suggest the best tutorial that will walk me through
I'm wondering if anyone can recommend a good C++ tree implementation, hopefully one that
I was wondering how can I set a timeout on a socket_read call? The
I'm wondering how can I submit a form via Ajax (using prototype framework) and
Wondering if anyone can help me with this annoying but trivial (in terms of
I'm wondering how you can implement a program similar to tail -f in C/C++,
I was wondering how i can force a user who has requested a page
I am wondering if someone can put a bit of an authoritative reference summary
I am wondering how I can break up my index.php homepage to multiple php
I was wondering if anyone can help me get started with creating a room

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.