Skip to content

SqlBulkCopy with concurrent request Deadlock issue in c# #3258

Open
@maulikhdave9601672767

Description

@maulikhdave9601672767

I m using Sqlbulkcopy with my application and trying to insert bulk 1000000 records in single table. But the approach is 10 Parallel threads will hit with bulk command on same table with 100000 record per each thread. while this thread ware running there will not be any update operation will happen on table. only read operation can happen same time from different thread.

using (SqlBulkCopy bulkCopy =
                new SqlBulkCopy(connectionString, SqlBulkCopyOptions.KeepIdentity))
            {
                bulkCopy.DestinationTableName =
                    "dbo.BulkCopyDemoMatchingColumns";

                try
                {
                    // Write from the source to the destination.
                    bulkCopy.WriteToServer(reader);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    // Close the SqlDataReader. The SqlBulkCopy
                    // object is automatically closed at the end
                    // of the using block.
                    reader.Close();
                }

I don't want any lock on my table and i also want to allow my all threads to bulk insert. I m using default option of bulk. how i can avoided Deadlock in this situation?

Metadata

Metadata

Assignees

Labels

Needs More Info ℹ️Issues that have insufficient information to pursue investigationsTriage Done ✔️Issues that are triaged by dev team and are in investigation.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions