Fix 3714 | Extract SqlBulkCopy column names using dynamic SQL#3719
Fix 3714 | Extract SqlBulkCopy column names using dynamic SQL#3719edwardneal wants to merge 2 commits intodotnet:mainfrom
Conversation
This enables the query to compile correctly when the graph_type column is missing
|
/azp run |
There was a problem hiding this comment.
Pull Request Overview
This PR modifies SqlBulkCopy to use dynamic SQL for column name extraction, enabling compatibility with SQL Server 2016. The change addresses compilation failures that occurred when querying the graph_type column on older SQL Server versions that don't support this column in the sys.all_columns DMV.
Key Changes:
- Converted static SQL queries to dynamic SQL using
sp_executesqlto defer compilation - Changed catalog name escaping from identifier-only to literal string escaping
- Updated test expectations to reflect additional SELECT operations from dynamic SQL execution
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| SqlBulkCopy.cs | Implements dynamic SQL execution for column queries and updates catalog name escaping to support parameterized queries |
| CopyAllFromReader.cs | Updates test assertions to account for increased SELECT count and rows from dynamic SQL execution |
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs
Show resolved
Hide resolved
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
@edwardneal - If you can merge main, I will kick off a new CI run. |
|
Thanks @paulmedynski, I've just merged. |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
This pull request has been marked as stale due to inactivity for more than 30 days. If you would like to keep this pull request open, please provide an update or respond to any comments. Otherwise, it will be closed automatically in 7 days. |
|
This PR is not stale. |
|
This pull request has been marked as stale due to inactivity for more than 30 days. If you would like to keep this pull request open, please provide an update or respond to any comments. Otherwise, it will be closed automatically in 7 days. |
|
This PR is not stale. |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
Since we want to move to the new version of 7 in the near future for EF10 support. Could this be considered for 7.0? After all it is a major update and SqlBulkCopy is used widely. Thanks in advance. |
agreed, this is a blocker here for 7.0 for me as well.. I'm not sure why it got bumped out of 7.0 again |
|
I've targeted this for the next hotfix, 7.0.1, as it's a regression. |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReader.cs
Show resolved
Hide resolved
|
Closing in favor of #4092, which cherry-picks this PR's changes onto the current main branch with an additional documentation comment addressing the Copilot review feedback. Thank you @edwardneal for the original contribution! |
Description
#3590 allowed SqlBulkCopy to find and work with hidden columns (even if those columns weren't accessible server-side.) It contained a check on the
all_columnsDMV to make sure that we only checked thegraph_typecolumn when querying if that column existed; this was to maintain SQL 2016 compatibility.#3714 highlighted that both queries are compiled and fail at the point of compilation anyway, so this wasn't accomplishing anything. To make this work, we need to use dynamic SQL to run the column queries. This PR does so.
It'll conflict with #3677, I'd appreciate it if we could review this first.
Issues
Testing
Manual testing of all test cases against a SQL 2016 instance.