Skip to content

Fix 3714 | Extract SqlBulkCopy column names using dynamic SQL#3719

Closed
edwardneal wants to merge 2 commits intodotnet:mainfrom
edwardneal:fix/3714-sqlbulkcopy-sql2016
Closed

Fix 3714 | Extract SqlBulkCopy column names using dynamic SQL#3719
edwardneal wants to merge 2 commits intodotnet:mainfrom
edwardneal:fix/3714-sqlbulkcopy-sql2016

Conversation

@edwardneal
Copy link
Copy Markdown
Contributor

@edwardneal edwardneal commented Oct 24, 2025

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_columns DMV to make sure that we only checked the graph_type column 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.

This enables the query to compile correctly when the graph_type column is missing
@edwardneal edwardneal requested a review from a team as a code owner October 24, 2025 21:42
@apoorvdeshmukh
Copy link
Copy Markdown
Contributor

/azp run

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_executesql to 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

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@github-project-automation github-project-automation bot moved this to To triage in SqlClient Board Oct 29, 2025
@edwardneal edwardneal changed the title Extract SqlBulkCopy column names using dynamic SQL Fix 3714 | Extract SqlBulkCopy column names using dynamic SQL Nov 16, 2025
@cheenamalhotra cheenamalhotra moved this from To triage to In review in SqlClient Board Nov 17, 2025
@paulmedynski
Copy link
Copy Markdown
Contributor

@edwardneal - If you can merge main, I will kick off a new CI run.

@edwardneal
Copy link
Copy Markdown
Contributor Author

Thanks @paulmedynski, I've just merged.

@paulmedynski
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 9, 2026

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.

@github-actions github-actions bot added the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Jan 9, 2026
@edwardneal
Copy link
Copy Markdown
Contributor Author

This PR is not stale.

@github-actions github-actions bot removed the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Jan 10, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 9, 2026

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.

@github-actions github-actions bot added the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Feb 9, 2026
@edwardneal
Copy link
Copy Markdown
Contributor Author

This PR is not stale.

@github-actions github-actions bot removed the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Feb 10, 2026
@cheenamalhotra cheenamalhotra added this to the 7.0.0-preview4 milestone Feb 10, 2026
@cheenamalhotra
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@samsharma2700 samsharma2700 self-assigned this Feb 10, 2026
@paulmedynski paulmedynski modified the milestones: 7.0.1, 7.1.0-preview1 Mar 11, 2026
@MarvinDrude
Copy link
Copy Markdown

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.

@nhart12
Copy link
Copy Markdown

nhart12 commented Mar 17, 2026

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

@mdaigle mdaigle modified the milestones: 7.1.0-preview1, 7.0.1 Mar 17, 2026
@mdaigle
Copy link
Copy Markdown
Contributor

mdaigle commented Mar 17, 2026

I've targeted this for the next hotfix, 7.0.1, as it's a regression.

@mdaigle mdaigle added the Regression 💥 Issues that are regressions introduced from earlier PRs. label Mar 17, 2026
@mdaigle mdaigle modified the milestones: 7.0.1, 7.1.0-preview1 Mar 18, 2026
@mdaigle
Copy link
Copy Markdown
Contributor

mdaigle commented Mar 18, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@paulmedynski
Copy link
Copy Markdown
Contributor

/azp run

@paulmedynski paulmedynski modified the milestones: 7.0.1, 7.1.0-preview1 Mar 25, 2026
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@paulmedynski
Copy link
Copy Markdown
Contributor

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!

@github-project-automation github-project-automation bot moved this from In review to Done in SqlClient Board Mar 26, 2026
@edwardneal edwardneal deleted the fix/3714-sqlbulkcopy-sql2016 branch March 26, 2026 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Regression 💥 Issues that are regressions introduced from earlier PRs.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

9 participants