Questions tagged [sqlbulkcopy]

Lets you efficiently bulk load a SQL Server table with data from another source.

The SqlBulkCopy class can be used to write data only to SQL Server tables. But the data source is not limited to SQL Server; any data source can be used, as long as the data can be loaded to a DataTable instance or read with a IDataReader instance.

Using the SqlBulkCopy class, you can perform:

  • A single bulk copy operation
  • List item Multiple bulk copy operations
  • List item A bulk copy operation within a transaction

Link to Microsoft Help Documentation: Microsoft SqlBulkCopy Documentation

964 questions
4
votes
2 answers

SQLBulkCopy Throws InvalidOperationException Nullable Ints

I have a DataTable that I am attempting to upload, but I run into the following exception: "The given value of type String from the data source cannot be converted to type int of the specified target column." The only reason I can think that it…
SeanVDH
  • 866
  • 1
  • 10
  • 28
4
votes
2 answers

Skip existing records when using SqlBulkCopy

I am trying to use SqlBulkCopy to copy rows from one SQL table to another. It works well up to the point when my destination table already contains a tuple with the primary key I am trying to add. Now all I am looking for is an option to skip the…
J. Doe
  • 53
  • 1
  • 5
4
votes
1 answer

Foreign key column allows 0 in SQL Server from bulk insert

I have a column that checks FK constraints on a column and allows NULL. However, it is allowing 0 as a value even though there is no row for ID of 0 in the primary table. This insert happens on a bulk insert with .NET. However, if I change the…
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341
4
votes
1 answer

SQL Server: Bulk Insert into table with computed column

I try to insert data from a textfile into a SQL Server 2016 table with a computed column with bcp. My bcp command: bcp Test.dbo.myFirstImport IN D:\myFirstImport.txt -f D:\myFirstImport.xml –T My table: CREATE TABLE [dbo].[MyFirstImport]( …
afj
  • 179
  • 1
  • 5
  • 13
4
votes
2 answers

Is there a faster way to use SqlBulkCopy than using a DataTable?

I load a large amount of records into my application (1 million+) and do a ton of processing on them. The processing requires them all to be in the memory. Afterwards, I want to dump all of the (now modified) records into an empty table. Loading the…
NibblyPig
  • 51,118
  • 72
  • 200
  • 356
4
votes
2 answers

Load CSV from Blob to Azure SQL Server - Referenced external data source not found

I'm trying to bulk insert a CSV hosted in blob storage into Azure SQL Server, as is described in this MSDN post. My code is taken almost entirely from this Microsoft Github sample. When running it I receive the following error: Referenced external…
Seafish
  • 2,081
  • 2
  • 24
  • 41
4
votes
3 answers

SqlBulkCopy throws System.FormatException when running WriteToServer(DataTable)

Currently I'm writing a method to read data from a CSV file and import to a SQL table. DataTable dt = new DataTable(); String line = null; int i = 0; while ((line = reader.ReadLine()) != null) { …
Leo
  • 2,173
  • 6
  • 28
  • 37
4
votes
1 answer

How to use the SQL Server JDBC bulk copy API

I run into some issues trying to map my column metadata with SQL Server Bulk Copy API and SQLServerBulkCSVFileRecord. Just for test purposes I made a table consisting of only nvarchar(500) columns and add the metadata like this: fileRecord = new…
Kim Lindqvist
  • 363
  • 4
  • 15
4
votes
1 answer

Importing a .CSV using SqlBulkCopy With ASP.Net Core

Hi I am trying to migrate some projects to ASP.Net Core and having some issues with what is the correct way to upload a .CSV file to my SQL database. In the past I would upload the .CSV file loop through it and store that information in a DataTable…
dev53
  • 404
  • 10
  • 26
4
votes
2 answers

sqlbulkcopy exception in production only

I am having a very strange behavior. When I test the application locally, everything works fine, with IIS Express, latest release of VisualStudio 2015 Update 3. But the live application running on IIS8 on Windows Server 2012, sometimes it…
Max Favilli
  • 6,161
  • 3
  • 42
  • 62
4
votes
5 answers

How to bulk copy sql (export) tables to a csv or tsv files in .Net?

Are there any .Net libraries that provide a way of exporting sql database data to plain text files (i.e. csv\tsv)? SqlBulkCopy only applies to the import part of the solution and I prefer not to be calling any Process.Start calls to open up command…
JK.
  • 185
  • 2
  • 15
4
votes
2 answers

Why do I get high fragmentation when using SqlBulkCopy to move large amounts data between databases?

Using the code Using bcp As New SqlBulkCopy(destConnection) bcp.DestinationTableName = "myOutputTable" bcp.BatchSize = 10000 bcp.WriteToServer(reader) End Using Where reader is an essentially an IDataReader that reads in a table,…
Paul
  • 101
  • 5
4
votes
2 answers

SqlBulkCopy inserts when inside a transaction prevents any other writes on a table

In my web app users can insert lots of data at once, to improve performance I am using the SqlBulkCopy class. It runs multiple times for a single operation inserting into two different tables. If the user cancels the operation or it fails then I…
user2945722
  • 1,293
  • 1
  • 16
  • 35
4
votes
2 answers

SqlBulkCopy insert order

To copy data from one database to another in different server with same schema, I am planning to use SqlBulkCopy class from C sharp library. Whether SqlBulkCopy will maintain the same order as it is in the datatable while inserting the records…
Rocky
  • 405
  • 7
  • 17
4
votes
1 answer

MySqlBulkLoader using a DataTable instead of a file

I'm providing MySql compatibility for my program that previously worked only with SQL Server. I used SqlBulkCopy and I would like to use it with MySql as well. I know there is MySqlBulkLoader that can be used to perform the same task. The difference…
disasterkid
  • 6,948
  • 25
  • 94
  • 179