You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SQL Bulk Copy Fails on SQL Server 2016 / 130 #3714
Since this PR #3590
SQL Bulk copy fails on SQL Server 2016. It may need to utilize dynamic sql instead of the IF statement because the query won't compile on older versions.
Invalid column name 'graph_type'.
To reproduce
To reproduce simply run the following query on an older version of SQL
SELECT @@TRANCOUNT;
DECLARE @Column_Names NVARCHAR(MAX) = NULL;
IF EXISTS (SELECT TOP 1 * FROM sys.all_columns WHERE [object_id] = OBJECT_ID('sys.all_columns') AND [name] = 'graph_type')
BEGIN
SELECT @Column_Names = COALESCE(@Column_Names + ', ', '') + QUOTENAME([name]) FROM {CatalogName}.[sys].[all_columns] WHERE [object_id] = OBJECT_ID('{escapedObjectName}') AND COALESCE([graph_type], 0) NOT IN (1, 3, 4, 6, 7) ORDER BY [column_id] ASC;
END
ELSE
BEGIN
SELECT @Column_Names = COALESCE(@Column_Names + ', ', '') + QUOTENAME([name]) FROM {CatalogName}.[sys].[all_columns] WHERE [object_id] = OBJECT_ID('{escapedObjectName}') ORDER BY [column_id] ASC;
END
Expected behavior
Bulk copy to succeed on older versions
Further technical details
Microsoft.Data.SqlClient version: found on main branch builds
.NET target: .net 8
SQL Server version: SQL Server 2016
Additional context
Reacted by MaceWindu, Patrick Parschau and yodasad
Maybe it's expected for > 7.0 to drop support for this version of sql server.. in which case the IF statement in SQL checking for that column seems redundant
Thanks. I added that IF statement specifically to account for SQL 2016, I'll fix it. This query works correctly on the earlier version (pending the extra logic to handle escaping of {CatalogName}.)
SELECT @@TRANCOUNT;
DECLARE @Object_ID INT= OBJECT_ID('{escapedObjectName}')
DECLARE @Column_Name_Query NVARCHAR(MAX) =NULL;
DECLARE @Column_Names NVARCHAR(MAX) =NULL;
IF EXISTS (SELECT TOP 1*FROMsys.all_columnsWHERE [object_id] = OBJECT_ID('sys.all_columns') AND [name] ='graph_type')
BEGINSET @Column_Name_Query = N'SELECT @Column_Names = COALESCE(@Column_Names + '', '', '''') + QUOTENAME([name]) FROM {CatalogName}.[sys].[all_columns] WHERE [object_id] = @Object_ID AND COALESCE([graph_type], 0) NOT IN (1, 3, 4, 6, 7) ORDER BY [column_id] ASC;'
END
ELSE
BEGINSET @Column_Name_Query = N'SELECT @Column_Names = COALESCE(@Column_Names + '', '', '''') + QUOTENAME([name]) FROM {CatalogName}.[sys].[all_columns] WHERE [object_id] = @Object_ID ORDER BY [column_id] ASC;'
END
EXEC sp_executesql @stmt = @Column_Name_Query,
@params = N'@Column_Names NVARCHAR(MAX) OUTPUT, @Object_ID INT',
@Column_Names = @Column_Names OUTPUT, @Object_ID = @Object_ID
SELECT @Column_Names
Activity
[-]SQL Bulk Copy Fails on SQL Server 130[/-][+]SQL Bulk Copy Fails on SQL Server 2016 / 130[/+]nhart12 commentedon Oct 23, 2025
Maybe it's expected for > 7.0 to drop support for this version of sql server.. in which case the IF statement in SQL checking for that column seems redundant
ErikEJ commentedon Oct 24, 2025
@edwardneal FYI
edwardneal commentedon Oct 24, 2025
Thanks. I added that IF statement specifically to account for SQL 2016, I'll fix it. This query works correctly on the earlier version (pending the extra logic to handle escaping of
{CatalogName}.)nhart12 commentedon Jan 7, 2026
@edwardneal any update on your PR here?
edwardneal commentedon Jan 7, 2026
Nothing as yet unfortunately, but it's ready for code review.
@dotnet/sqlclientdevteam is there enough time to merge #3719 prior to preview4?
andreascaesar commentedon Mar 19, 2026
I haven't investigated the proposed fix, but it is the same error in SQL Server 2014, which (unfortunately) is in extended support for another year...
Can someone confirm that this will be fixed in 2014 also?
bifacil commentedon Mar 24, 2026
This random error appears after upgrading from Microsoft.Data.SqlClient 6.1.4 to 7.0.
My tables don't have any 'graph_type' column...
2 remaining items
paulmedynski commentedon Mar 26, 2026
The fix for this issue has moved from #3719 to #4092, which is based on the current main branch.
Welchen commentedon Apr 20, 2026
Is there a manual workaround for this as 7.0.1 is not released yet? We just ran into this after upgrading to 7.0.0
ErikEJ commentedon Apr 20, 2026
@Welchen use 6.1.4 !?
Welchen commentedon Apr 20, 2026
We upgraded to solve some binary collisions we were having since 7.0.0 started using .NET 10 dependencies.
ErikEJ commentedon Apr 20, 2026
@Welchen 7.0.1 is currently planned for this week, it might actually happen
Bump the nuget-all group with 3 updates (#102)
Bump Microsoft.Data.SqlClient from 6.1.6 to 7.1.0 (#66)