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
6
votes
3 answers

How to retrieve server generated Identity values when using SqlBulkCopy

I know I can do a bulk insert into my table with an identity column by not specifying the SqlBulkCopyOptions.KeepIdentity as mentioned here. What I would like to be able to do is get the identity values that the server generates and put them in my…
dseiple
  • 598
  • 2
  • 6
  • 17
6
votes
1 answer

Getting SqlBulkCopy to show up as sql in MiniProfiler

I'm using MiniProfiler to profile my sql commands. One issue I'm dealing with now is repeated INSERT statements generated by linq. I've converted them into a SqlBulkCopy command, however now it doesn't appear to record it in the sql view in…
George Duckett
  • 31,770
  • 9
  • 95
  • 162
6
votes
3 answers

Getting an exception writing a boolean to sql using a datatable and SqlBulkCopy

It works fine for all other datatypes, but I am unable to get it to work with a 'bit' column. This is my SQL for doing the bulk write: using (var bulk = new SqlBulkCopy(connectionString, SqlBulkCopyOptions.KeepIdentity &…
NibblyPig
  • 51,118
  • 72
  • 200
  • 356
6
votes
4 answers

SQL Bulk Copy "The given value of type String from the data source cannot be converted to type datetime of the specified target column" using ASP.NET

I'm working on an ASP.NET MVC4 projet and I'm trying to export data from an xlsx file (Excel 2010 file) to my database by using SQL Bulk Copy. My Excel file contains only 2 columns : the first contains numbers (from 1 to 25) and the second contains…
Traffy
  • 2,803
  • 15
  • 52
  • 78
6
votes
2 answers

Bulk copy with dynamic created temp table in ADO.NET

I require to create through ADO.NET a temp table, perform a BulkCopy and then a Merge on the server between the temp and the actual table. Problem is creating the temp table dynamic using pure ADO.NET. The schema should be the same as the existing…
Ronald
  • 1,990
  • 6
  • 24
  • 39
5
votes
1 answer

How do I efficiently store all OpenStreetMap data in an indexed way?

Note: While I target Windows Phone 7, it doesn't introduce anything besides a size restriction. In an attempt to write a GPS / Routing / Map application for the Windows Phone 7, I'm trying to attempt to use OpenStreetMap for this and I want to get…
Tamara Wijsman
  • 12,198
  • 8
  • 53
  • 82
5
votes
1 answer

EF Competing SaveChanges() Calls

I am building a batch processing system. Batches of Units come in quantities from 20-1000. Each Unit is essentially a hierarchy of models (one main model and many child models). My task involves saving each model hierarchy to a database as a…
Jeff Swensen
  • 3,513
  • 28
  • 52
5
votes
1 answer

What is the difference between polybase and bulk insert, copy methods in azure data factory and when to use them?

Can some one please elaborate on when to use Polybase versus bulk insert in azure datafactory, what are the differences between these two copy methods?
Indra
  • 51
  • 1
  • 1
  • 2
5
votes
2 answers

SQL Bulk insert with parent/child relationships, is order preserved?

Similar to these other questions noted below, I have two tables with the structure: create table parent ( recno int identity(1,1) primary key not null, groupCode int, parentdata varchar(80) ); create table child ( parentrecno int not…
Clinton Pierce
  • 12,859
  • 15
  • 62
  • 90
5
votes
0 answers

EFCore.BulkExtensions fails to do insert with Guid PK

I am using EFCore.BulkExtensions to insert an entity with a GUID / UniqueIdentifier primary key into my database, but I am receiving the following exception when I call this line: System.InvalidOperationException HResult=0x80131509 Message=The …
CShark
  • 2,183
  • 1
  • 24
  • 42
5
votes
3 answers

C# Optimisation: Inserting 200 million rows into database

I have the following (simplified) code which I'd like to optimise for speed: long inputLen = 50000000; // 50 million DataTable dataTable = new DataTable(); DataRow dataRow; object[] objectRow; while (inputLen--) { objectRow[0] = ... …
David Tang
  • 92,262
  • 30
  • 167
  • 149
5
votes
1 answer

Retryable SQLBulkCopy for SQL Server 2008 R2

I am basically from database background and new to .net stuff. Please bear with me if my question sounds silly. I am using SqlBulkCopy in my code to transfer data from one SQL Server to other. But it is failing frequently due to network issues. To…
SumanKumar
  • 344
  • 5
  • 19
5
votes
1 answer

How do I make SqlBulkCopy work with MS Enterprise Library?

I've got some code which uses SqlBulkCopy. And now we're refactoring our code to use Enterprise Library database functions instead of standard ones. The question is how can I instantiate SqlBulkCopy? It accepts SqlConnection, and I only have…
HiveHicks
  • 2,294
  • 5
  • 28
  • 42
5
votes
1 answer

Timeout on SqlBulkCopy in Azure

We're having an issue with SqlBulkCopy in Azure. Context is as follow: We have a table with approximately 10 million rows. Each row has about 15 columns. We're migrating that data into our new model and this requires a split of the data so 1 row…
Georges Legros
  • 2,494
  • 2
  • 23
  • 42
5
votes
1 answer

Sqlbulkcopy doesn't seem to work for me

I have created a datatable and trying to insert that datatable through SqlBulkCopy but somehow it doesn't seem to work for me.... I got the error, The given value of type DateTime from the data source cannot be converted to type decimal of the…
ACP
  • 34,682
  • 100
  • 231
  • 371