

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON To be honest, I don't know enough to know if I should alter that.Īnd here is the non-clustered index that's also on the table: CREATE NONCLUSTERED INDEX ON. ADD CONSTRAINT DEFAULT ('') FOR ĪLTER TABLE. ADD CONSTRAINT DEFAULT ((0)) FOR ĪLTER TABLE. ADD CONSTRAINT DEFAULT (getdate()) FOR ĪLTER TABLE. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON ĪLTER TABLE. (100) NOT NULL,ĬONSTRAINT PRIMARY KEY CLUSTERED Here is the table's schema, generated from a create script: SET ANSI_NULLS ON The number of rows can vary, but the high end might be something like 4,000. String destColumn = columnNames.Single(x => x.Equals(column.ColumnName, StringComparison.OrdinalIgnoreCase)) ī(column.ColumnName, destColumn) Īwait bulkCopy.WriteToServerAsync(dataTableWithEnumStrings) įrom what I can tell, it looks like a page lock. The column mappings are case sensitive, so grab the destination column so we can use its casing. Add column mappings so we don't have to worry about order when adding new columns/properties.įoreach (DataColumn column in dataTableWithEnumStrings.Columns) Var dataTableWithEnumStrings = ConvertDataTableEnum(dataTable) Var dataTable = ToDataTable(histories, columnNames) Here is the bulk copy code: using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnection, SqlBulkCopyOptions.Default, sqlTransaction))īulkCopy.DestinationTableName = destinationTableName Both the victim and blockers show the same SQL statements.
#SQL SERVER DEADLOCK 256 CODE#
This is the line of code that does the inserts: await bulkCopy.WriteToServerAsync(dataTableWithEnumStrings) Should it be possible for deadlocks to occur in this scenario? They are done within a transaction. And that table's PK is an identity column. The bulk inserts are inserting into the same table. But a colleague mentioned it shouldn't be possible with my setup. I think these simultaneous bulk inserts are the reason why the deadlock is occurring. The deadlock usually happens, but not always. Using a message bus, many subscribers can end up doing a bulk insert at roughly the same time.
#SQL SERVER DEADLOCK 256 HOW TO#
Summary: in this tutorial, you’ll learn about the SQL Server deadlock and how to simulate a deadlock.
