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
5
votes
4 answers

Fire trigger for every inserted row using SqlBulkCopy

I am using SqlBulkCopy class to insert 50k rows at a time in table tbl_records I have set a After Insert trigger on this table and using following code SqlBulkCopy SqlBc1 = new SqlBulkCopy(strConnString, SqlBulkCopyOptions.FireTriggers); // Set…
Rajeev Kumar
  • 4,901
  • 8
  • 48
  • 83
5
votes
1 answer

Get the count of rows from a COPY command

When copying data from a file, you get the count of rows in psql with the "command tag": db=# COPY t FROM '/var/lib/postgres/test.sql'; COPY 10 I need the number of rows and would like to avoid a redundant count() on the table. Is there a way to get…
Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
5
votes
3 answers

Unable to read first row from Excel using SqlBulkCopy

I am using following code to update an Excel file into SQL Server. Code is working but it is not able to insert first row into table. OleDbConnection OleDb = new OleDbConnection(ConnectionString); OleDbCommand OleDbCmm = new…
ravi
  • 1,300
  • 2
  • 11
  • 17
5
votes
4 answers

BulkCopy error: The locale id '1025' of the source column 'CreatedBy' and the locale id '1033' of the destination column 'CreatedBy' do not match

I’m performing SQL bulk copy using the SqlBulkCopy class. I created my destination table to be exactly the same of my source table. They both have the same table name, columns names, data types and even the same collation. I did also the sql mapping…
dantee_87
  • 71
  • 1
  • 7
5
votes
1 answer

LINQ Entity Data Reader does not support enums

I have to do a batch insert of a lot of entities, so I figured the best way to do that was to use the SqlBulkCopy class. However, that class operates on DataReader instances, whereas my code works with an IEnumerable where T is my entity class. To…
Erik Schierboom
  • 16,301
  • 10
  • 64
  • 81
5
votes
2 answers

Exception and memory Issue in SQL Bulk Copy

We are using SQL bulk copy to insert nearly 10 million rows into a SQL Server table. We received this exception after 7400000 insertions: OLE DB provider 'STREAM' for linked server '(null)' returned invalid data for column…
User87
  • 91
  • 1
  • 3
5
votes
2 answers

Automatically define the DataTable in C# from the schema of SQL server tables?

I already have some tables in SQL Server and I am writing a C# program to populate the tables from some flat files. I plan to use SQLBulkCopy to load the tables. It can be a lot of work to define all the columns for each DataTable for SQLBulkCopy.…
ca9163d9
  • 27,283
  • 64
  • 210
  • 413
5
votes
2 answers

SQLBulkCopy with Identity Insert in destination table

I am trying to insert a Generic list to SQL Server with SQLBulkCopy, And i have trouble wit Identity Field I wan t my destination table to generate identity field How should i handle this, here is my code using (var bulkCopy = new…
HaBo
  • 13,999
  • 36
  • 114
  • 206
4
votes
3 answers

C# SqlBulkCopy types mismatch

I have a DataTable which has 10 columns, and after I add some rows in it, I want to add it to the database using SqlBulkCopy. My problem is that in the DataTable I have strings and some fields in the database are decimal and date respectively. Is…
Rocshy
  • 3,391
  • 11
  • 39
  • 56
4
votes
6 answers

How do I read a large file from disk to database without running out of memory

I feel embarrassed to ask this question as I feel like I should already know. However, given I don't....I want to know how to read large files from disk to a database without getting an OutOfMemory exception. Specifically, I need to load CSV (or…
Mr Moose
  • 5,946
  • 7
  • 34
  • 69
4
votes
1 answer

Delete not working in transaction with sql bulk insert

I need to delete some records from table and then insert some records to the same table. This delete and insert process should be in transaction. Below is what i did. using (SqlConnection sqlConn = new SqlConnection(connectionString)) { …
Muthukumar
  • 8,679
  • 17
  • 61
  • 86
4
votes
1 answer

How can I set column type when using SqlBulkCopy to insert into a sql_variant column

I'm using SqlBulkCopy to insert/update from a .net DataTable object to a SQL Server table that includes a sql_variant column. However SqlBulkCopy insists on storing DateTime values put into that column as sql type 'datetime' when what I need is…
BowserKingKoopa
  • 2,701
  • 3
  • 33
  • 40
4
votes
3 answers

Guid.NewGuid() is returning duplicate values when used in a Parallel.For loop

I have an application that is hitting an API. As such, it does a query for all ID's in the object, and then has to query each item one at a time per ID. I'm doing this in a Parallel.For loop and adding each items data to a row in a datatable. …
Mike Jones
  • 51
  • 8
4
votes
2 answers

How to implement the interface IDataReader in order to process the data before being insert?

I have a stored procedure which gives me a result set consisting of a single column which contains millions of unprocessed rows. I need to transfer these data to another server using SqlBulkCopy, but the problem is that I can't simply do the…
J. Doe
  • 63
  • 1
  • 5
4
votes
1 answer

java.lang.NoSuchMethodError: com.microsoft.sqlserver.jdbc.SQLServerBulkCopyOptions.setAllowEncryptedValueModifications(Z)V

I am trying to utilize the bulkCopyToSqlDB function for the microsoft sql server jdbc driver with the sql spark connector found here. This is the syntax to launch the spark shell: spark-shell --jars…
John
  • 41
  • 4