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
26
votes
8 answers

SQLBulkCopy Row Count When Complete

I am using SQLBulkCopy to move large amounts of data. I implemented the notification event to notify me every time a certain number of rows have been processed, but the OnSqlRowsCopied event does not fire when the job is completed. How do I get…
SchwartzE
  • 2,558
  • 5
  • 30
  • 39
22
votes
1 answer

Does SqlBulkCopy automatically start a transaction?

I am inserting data via SqlBulkCopy like so: public void testBulkInsert(string connection, string table, DataTable dt) { using (SqlConnection con = new SqlConnection(connection)) { con.Open(); using (SqlBulkCopy bulkCopy =…
Dan
  • 45,079
  • 17
  • 88
  • 157
22
votes
1 answer

C# Bulk Insert SQLBulkCopy - Update if Exists

Possible Duplicate: Any way to SQLBulkCopy “insert or update if exists”? I am using SQLBulkCopy to insert Bulk records How can I perform on update (rather than an insert) on records that already exist? Is this possible with SQLBulkCopy? This is…
HaBo
  • 13,999
  • 36
  • 114
  • 206
20
votes
10 answers

SqlBulkCopy cannot access table

After reading in an excel-sheet (to transferTable), I want to add that data to a new table (destinationTable) using SqlBulkCopy, but I'm getting the error: Cannot access destination table 'test' I've tried using the default tablename and using…
SND
  • 1,552
  • 2
  • 16
  • 29
20
votes
7 answers

SqlBulkCopy Not Working

I have a DataSet populated from Excel Sheet. I wanted to use SQLBulk Copy to Insert Records in Lead_Hdr table where LeadId is PK. I am having following error while executing the code below: The given ColumnMapping does not match up with any column…
Sandhurst
20
votes
2 answers

Million inserts: SqlBulkCopy timeout

We already have a running system that handles all connection-strings (db2, oracle, MSServer). Currently, We are using ExecuteNonQuery() to do some inserts. We want to improve the performance, by using SqlBulkCopy() instead of ExecuteNonQuery(). We…
billybob
  • 2,859
  • 6
  • 35
  • 55
19
votes
3 answers

Fastest way to insert 30 thousand rows in a temp table on SQL Server with C#

I am trying to find out how I can improve my insert performance in a temporary table in SQL Server using c#. Some people are saying that I should use SQLBulkCopy however I must be doing something wrong as it seems to work much slower than simply…
Jenninha
  • 1,357
  • 2
  • 20
  • 42
18
votes
7 answers

How to prevent duplicate records being inserted with SqlBulkCopy when there is no primary key

I receive a daily XML file that contains thousands of records, each being a business transaction that I need to store in an internal database for use in reporting and billing. I was under the impression that each day's file contained only unique…
kscott
  • 1,866
  • 3
  • 25
  • 41
18
votes
4 answers

Weird "OLE DB provider 'STREAM' for linked server '(null)' returned invalid data for column '[!BulkInsert].Value' error

Software used: Windows 7 64 bit Ultimate, .Net 4, SQL Server 2008 R2. select @@version returns: Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (X64) Apr 22 2011 19:23:43 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on…
boggy
  • 3,674
  • 3
  • 33
  • 56
18
votes
3 answers

Error inserting data using SqlBulkCopy

I'm trying to batch insert data into SQL 2008 using SqlBulkCopy. Here is my table: IF OBJECT_ID(N'statement', N'U') IS NOT NULL DROP TABLE [statement] GO CREATE TABLE [statement]( [ID] INT IDENTITY(1, 1) NOT NULL, [date] DATE NOT NULL DEFAULT…
abatishchev
  • 98,240
  • 88
  • 296
  • 433
17
votes
7 answers

SqlBulkCopy and Entity Framework

My current project consists of 3 standard layers: data, business, and presentation. I would like to use data entities for all my data access needs. Part of the functionality of the app will that it will need to copy all data within a flat file…
Skadoosh
  • 2,575
  • 8
  • 40
  • 53
16
votes
2 answers

SqlBulkInsert - How to set Fire Triggers, Check Constraints?

I'm performing a bulk insert with an ADO.NET 2.0 SqlBulkCopy object from a C# method into a MS SQL 2005 database, using a database user with limited permissions. When I try to run the operation, I get the error message: Bulk copy failed. User does…
James Orr
  • 5,005
  • 7
  • 39
  • 63
15
votes
1 answer

SQLBulkCopy or Bulk Insert

I have about 6500 files for a sum of about 17 GB of data, and this is the first time that I've had to move what I would call a large amount of data. The data is on a network drive, but the individual files are relatively small (max 7 MB). I'm…
SeanVDH
  • 866
  • 1
  • 10
  • 28
15
votes
4 answers

Skip some columns in SqlBulkCopy

I'm using SqlBulkCopy against two SQL Server 2008 with different sets of columns (going to move some data from prod server to dev). So want to skip some columns not yet existed / not yet removed. How can I do that? Some trick with…
abatishchev
  • 98,240
  • 88
  • 296
  • 433
15
votes
4 answers

sqlbulkcopy using sql CE

Is it possible to use SqlBulkcopy with Sql Compact Edition e.g. (*.sdf) files? I know it works with SQL Server 200 Up, but wanted to check CE compatibility. If it doesnt does anyone else know the fastest way of getting a CSV type file into SQL…
Mark H
  • 707
  • 1
  • 11
  • 21
1
2
3
64 65