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 939235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:45:27+00:00 2026-05-15T21:45:27+00:00

I am using SqlBulkCopy to import from an external DB. When importing into an

  • 0

I am using SqlBulkCopy to import from an external DB. When importing into an nvarchar column, if the column isn’t big enough to hold the incoming string, it fails with:

InvalidOperationException: The given value of type String from the data source cannot be converted to type nvarchar of the specified target column. String or binary data would be truncated.

I’d sure like to be able to tell the user what target column had the problem. I’ve combed through the exception, but don’t see it anywhere. Is there a way to set things up so the name or index of the column comes back in the exception?

Here is the pseudo code of my bulk copy:

using (DbConnection source = DataTableProviderAssists.GetTypedDbConnection(package.ImportSourceType, package.UnencryptedConnectionString))
{
    using (DbCommand cmd = GetCommand(package, source))
    {
        source.Open();

        reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

        using (SqlBulkCopy bulkCopy = new SqlBulkCopy(RequestContext.ConnectionString, SqlBulkCopyOptions.TableLock))
        {
            bulkCopy.DestinationTableName = temporaryTableName;
            bulkCopy.BatchSize = 40000;
            bulkCopy.BulkCopyTimeout = 60000;

            foreach (ImportField field in package.Fields)
            {
                bulkCopy.ColumnMappings.Add(field.Name, field.Name);
            }

            bulkCopy.WriteToServer(reader);
        }
    }
}

Thanks

  • 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-15T21:45:27+00:00Added an answer on May 15, 2026 at 9:45 pm

    I am not sure that there is.
    You may need to tackle this one in a different way.
    Try using Microsoft.SqlServer.Management.Smo API to query your destination table, and figure out what the maximum length of the columns in your table are.
    Once you have those, you can pre-read your source data, and fire exceptions immediately.
    Have fun.

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

Sidebar

Related Questions

I'm using SqlBulkCopy to bulk insert some records from one table into another table.
Using import datetime in python, is it possible to take a formatted time/date string
I'm using SQLBULKCOPY to copy some data-tables into a database table, however, because the
I'm having proplems with importing an XML file using SqlBulkCopy . The XML file
I am using SqlBulkCopy object to write a datatable into an sql server table.
I am using the SqlBulkCopy object to insert a couple million generated rows into
I'm trying to import some data from excel into a database . i got
What's the best way to import a small csv file into SQL Server using
I'm using SqlBulkCopy to restore tables from xml backups. One of the table backup
I saw lots of articles talking about using SqlBulkCopy to copy content from csv

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.