Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BullkMerge: The MERGE statement attempted to UPDATE or DELETE the same row more than once. #743

Open
nuqlium opened this issue Nov 6, 2022 · 11 comments
Assignees

Comments

@nuqlium
Copy link

nuqlium commented Nov 6, 2022

Hi,

There is an error when doing a bulkMerge.

========
System.Data.SqlClient.SqlException (0x80131904): The MERGE statement attempted to UPDATE or DELETE the same row more than once. This happens when a target row matches more than one source row. A MERGE statement cannot UPDATE/DELETE the same row of the target table multiple times. Refine the ON clause to ensure a target row matches at most one source row, or use the GROUP BY clause to group the source rows.

Capturing the values, would the first item which looks like superscript and the normal "3" cause the package to treat them the same way and thus think we have duplicate keys? Is there a way around this.

["³","3","womans coat","m","0m3p4kvt-1"]

Any help would be greatly appreciated.

Thank you,
Dev

@JonathanMagnan JonathanMagnan self-assigned this Nov 7, 2022
@JonathanMagnan
Copy link
Member

Hello @nuqlium ,

This error happens when the source has multiple entities with the same key values.

You need to use the AllowDuplicateKeys = true option to fix this issue.

Example: https://dotnetfiddle.net/DoD5hE

Best Regards,

Jon

@nuqlium
Copy link
Author

nuqlium commented Nov 7, 2022

Hi Jon,

Thank you for the feedback, appreciate the time.

I don't think the source has the same key.
I believe the two values here are different.

["³","3"]

One is effectively superscript and one is normal.
These values have different Unicode SQL values.
https://theasciicode.com.ar/extended-ascii-code/superscript-three-exponent-3-cube-third-power-ascii-code-252.html

Is there an option within BulkMerge to treat these values separately?

(Edit: This is why I don't think AllowDuplicateKeys is the answer, as they're not duplicates and if I set that value=true, then I may end up with two entries for the same key which are actually different keys - I think!)

The field they go into is an NVARCHAR which supports these characters.

Thank you again for your assistance,
Apologies if I've got this wrong,

Dev

@JonathanMagnan
Copy link
Member

Hello @nuqlium ,

Do you think you could create a runnable project with the issue? It doesn’t need to be your project, just a new solution with the minimum code to reproduce the issue. You can send it in private here: info@zzzprojects.com

Perhaps we are missing something, as we don't fully see the current code.

SQL Server should already treat those numbers/characters differently since as you said, there have different unicode values.

@nuqlium
Copy link
Author

nuqlium commented Nov 11, 2022 via email

@JonathanMagnan
Copy link
Member

Hello @nuqlium,

Since our last conversation, we haven't heard from you.

Let me know if you need further assistance.

Best regards,

Jon

@nuqlium
Copy link
Author

nuqlium commented Nov 23, 2022 via email

@JonathanMagnan
Copy link
Member

Hello again,

A simple reminder that we are here to assist you.

Don't hesitate to contact us if you need anything.

Best regards,

Jon

@JonathanMagnan
Copy link
Member

Hello again,

Since our last conversation, we haven't heard from you.

Did your team find the time to create a project for this issue?

Let me know if you need further assistance.

Best regards,

Jon

@nuqlium
Copy link
Author

nuqlium commented Dec 19, 2022 via email

@JonathanMagnan
Copy link
Member

Hello again!

Let me know if you need further assistance.

Best regards,

Jon

@nuqlium
Copy link
Author

nuqlium commented Jan 9, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants