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
9
votes
1 answer

what does sp_tablecollations_100 do?

Just before a bulkinsert (SqlBulkCopy) I see a excec sp_tablecollations_100 N'.tb_tablename' in the profiler What does this do? Is it a sign of a problem or is it normal? Thanks for your help update the bulik insert afterwards show with the…
Pleun
  • 8,856
  • 2
  • 30
  • 50
9
votes
2 answers

bulkcopy with primary key not working

I have a database table, with columns and a priamary key. I want to do the bulkcopy, from a datatable in my c#. When I have primary key in my table, I got exception because the table has 6 columns, while my datatable has just 5. what should I do…
Marco Dinatsoli
  • 10,322
  • 37
  • 139
  • 253
9
votes
1 answer

How to get identities of inserted data records using SQL bulk copy

I have an ADO.NET DataTable with about 100,000 records. In this table there is a column xyID which has no values in it, because the column is an auto-generated IDENTITY in my SQL Server database. I need to retrieve the generated IDs for other…
Olga
  • 1,516
  • 5
  • 17
  • 23
9
votes
4 answers

Is there a way to use SqlBulkCopy without converting the data to a DataTable?

Is there a way to use SqlBulkCopy without converting the data to a DataTable? I have a list of objects (List) in RAM and I really don't want to use more memory to create the DataTable. Could it be possible to implement IDataReader on a List? Thanks!
Martin
  • 39,309
  • 62
  • 192
  • 278
9
votes
4 answers

Using SQLBulkCopy to Insert/Update database

I have a datatable with the records.I'm inserting records into Sql table using SqlBulkCopy.It works fine.Next time when get the datatable with same records with few changed values SqlBulkCopy is inserting another set of records without updating the…
vix
  • 91
  • 1
  • 1
  • 2
9
votes
1 answer

sqlbulkcopy - does not allow DBNull.Value.?

I am trying these 2 calls below but both of them returns me an exception Customer_ID does not allow DBNull.Value. but when I debug, I see that all my records have Customer_ID assigned. It is the only one as not nullable defined on my DB table. what…
Emil
  • 6,411
  • 7
  • 62
  • 112
8
votes
2 answers

SqlBulkCopy DataTable with WellKnownText spatial data column

I'm trying to bulk copy a DataTable which has the following columns: "ID" - System.Int32 "Geom" - System.String Into a SQL database with the following columns: "Id" - int "Shape" - geometry Can anyone advise on the best way to do this? Some…
mortware
  • 1,910
  • 1
  • 20
  • 35
8
votes
3 answers

SqlBulkCopy into table that Default column values fails when source DataTable row has DBNull.Value

Update: Here is my solution I have a table defined as: CREATE TABLE [dbo].[csvrf_References] ( [Ident] [int] IDENTITY(1,1) NOT NULL, [ReferenceID] [uniqueidentifier] NOT NULL DEFAULT (newsequentialid()), [Type] [nvarchar](255) NOT NULL, …
James Nix
  • 885
  • 1
  • 6
  • 19
8
votes
2 answers

Precision Lost while Bulk Inserting records into SQL using SqlBulkCopy

I am using the following code to Bulk Insert a data table into my SQL Table: // Set up the bulk copy object. using (SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection.Connection)) …
Hassan Mokdad
  • 5,832
  • 18
  • 55
  • 90
8
votes
1 answer

SqlBulkCopy performance

I am working to increase the performance of bulk loads; 100's of millions of records + daily. I moved this over to use the IDatareader interface in lieu of the data tables and did get a noticeable performance boost (500,000 more records a minute).…
Michael S
  • 83
  • 1
  • 2
  • 6
8
votes
4 answers

Inserting GUIDs with SqlBulkCopy

I'm trying to do a bulk insert with the SqlBulkCopy class from flatfiles created by the SQL Server Management Import Export Wizard. The files are comma separated. One row in the file can look like…
Magnus A
  • 83
  • 1
  • 1
  • 5
7
votes
2 answers

Parallel Bulk Inserting with SqlBulkCopy and Azure

I have an azure app on the cloud with a sql azure database. I have a worker role which needs to do parsing+processing on a file (up to ~30 million rows) so i can't directly use BCP or SSIS. I'm currently using SqlBulkCopy, however this seems too…
7
votes
3 answers

How to insert a constant value into a column using ASP.Net SqlBulkCopy

In the below code, I am trying insert the records from excel to Database table, but an additional column is not passed through the excel, which has to be populated with a constant value(foreach loop with a different value) assigned from the…
Ganesha
  • 342
  • 1
  • 3
  • 8
7
votes
1 answer

How to efficiently invoke table-valued parameters from Ado.Net

I need to efficiently submit tens of thousands of numbers and dates from Ado.Net to SQl Server 2008. Back in the days, before SQL 2008, I was packing those numbers in an image, which was quite fast. Erland Sommarskog was kind enough to include some…
A-K
  • 16,804
  • 8
  • 54
  • 74
7
votes
5 answers

Bulk C# datatable to postgresql table

I have got a datatable with thousands of records. I have got a postgres table with the same fields of the datatable. I want everyday to truncate this table and fill again with the data of the datatable. I have seen sql bulk copy, but it is not…
Za7pi
  • 1,338
  • 7
  • 22
  • 33