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

Bug: Incorrect syntax near the keyword 'WITH' BulkMergeAsync #640

Closed
stefandevo opened this issue Nov 9, 2020 · 7 comments · Fixed by #642
Closed

Bug: Incorrect syntax near the keyword 'WITH' BulkMergeAsync #640

stefandevo opened this issue Nov 9, 2020 · 7 comments · Fixed by #642
Assignees
Labels
bug Something isn't working deployed Feature or bug is deployed at the current release fixed The bug, issue, incident has been fixed. for grabs A community can grab for contribution

Comments

@stefandevo
Copy link
Contributor

I tried

var mergedRows = await connection.BulkMergeAsync(syncConsumers, batchSize: 1000, hints: SqlServerTableHints.NoLock, bulkCopyTimeout: 300);

This caused

System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near the keyword 'WITH'.
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
Incorrect syntax near the keyword 'AS'.

If I remove the hints then it worked. Note that I used the same hint for the BulkInsert command with success.

Is there an option to get the last generated SQL statement in such cases to further see what could be wrong?

BTW: Great lib!

@mikependon
Copy link
Owner

Hey, thanks for reporting, we will look into this. When do you need the fix?

@mikependon mikependon self-assigned this Nov 9, 2020
@stefandevo
Copy link
Contributor Author

Not urgent; just wanted to report; I removed the hints for now as it's not crucial at the moment.

@mikependon
Copy link
Owner

@stefandevo - I had investigated this one. The fix is very simple, we just have to switch the line 526 and line 527 from the SqlConnectionExtension.cs class.

Would you be able to provide a PR for this? Your help is highly appreciated - that matters and counts. TIA

@mikependon mikependon added bug Something isn't working for grabs A community can grab for contribution labels Nov 13, 2020
@mikependon mikependon changed the title Incorrect syntax near the keyword 'WITH' BulkMergeAsync Bug: Incorrect syntax near the keyword 'WITH' BulkMergeAsync Nov 13, 2020
@stefandevo
Copy link
Contributor Author

Hi @mikependon no problem, but investigated the source and I see same for GetBulkUpdateSqlText, GetBulkDeleteSqlText. The Insert statement is the only one where the table alias is not place, and so the hints are added after the tableName.

@mikependon
Copy link
Owner

Cool and thanks for sleuthing around ;) - see my Tweet here. Therefore, you do not need to worry the other methods IMO.

Also, the RepoDb.SqlServer method CreateMerge has the proper ordering, unlike the one in the BulkOperations.

@mikependon
Copy link
Owner

The fixes for this is now available on the version >= RepoDb.SqlServer.BulkOperations v1.1.2-beta1. Please upgrade your copy by simply typing the command below in your PCM.

> Install-Package RepoDb.SqlServer.BulkOperations -version 1.1.2-beta1

Thank you for the PR in relation to this issue.

@mikependon mikependon added deployed Feature or bug is deployed at the current release fixed The bug, issue, incident has been fixed. labels Nov 13, 2020
@mikependon
Copy link
Owner

Closing this one now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working deployed Feature or bug is deployed at the current release fixed The bug, issue, incident has been fixed. for grabs A community can grab for contribution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants