-
Notifications
You must be signed in to change notification settings - Fork 316
Closed
Description
Describe the bug
When using SqlBulkCopy to bulk insert data into a column with enabled SQL "SENSITIVITY CLASSIFICATION" the WriteToServer Method throws a System.InvalidOperationException.
Exception message: System.InvalidOperationException: Internal connection fatal error.
Stack trace: at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at Microsoft.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at Microsoft.Data.SqlClient.SqlBulkCopy.RunParser(BulkCopySimpleResultSet bulkCopyHandler)
at Microsoft.Data.SqlClient.SqlBulkCopy.CreateAndExecuteInitialQueryAsync(BulkCopySimpleResultSet& result)
at Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerInternalRestAsync(CancellationToken cts, TaskCompletionSource`1 source)
--- End of stack trace from previous location where exception was thrown ---
at SqlBulkCopy.Sample.Program.Main(String[] args) in C:\Users\raphael.CODEWORX\source\repos\SqlBulkCopy.Sample\SqlBulkCopy.Sample\Program.cs:line 35
at SqlBulkCopy.Sample.Program.<Main>(String[] args)
To reproduce
Include a complete code listing (or project/solution) that we can run to reproduce the issue.
Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.
CREATE DATABASE [BulkTest]
GO
USE [BulkTest]
GO
CREATE TABLE [dbo].[Company](
[CompanyId] [uniqueidentifier] NOT NULL,
[CompanyName] [nvarchar](255) NOT NULL,
[Email] [nvarchar](50) NULL,
[CompanyType] [int] not null,
CONSTRAINT [PK_Company] PRIMARY KEY CLUSTERED
(
[CompanyId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
ADD SENSITIVITY CLASSIFICATION TO [dbo].[Company].[Email] WITH (label = 'Confidential', label_id = 'c185460f-4e20-4b89-9876-ae95f07ba087', information_type = 'Contact Info', information_type_id = '5c503e21-22c6-81fa-620b-f369b8ec38d1');static async Task Main(string[] args)
{
var data = new DataTable("Company");
data.Columns.Add("CompanyId", typeof(Guid));
data.Columns.Add("CompanyName", typeof(string));
data.Columns.Add("Email", typeof(string));
data.Columns.Add("CompanyType", typeof(int));
data.Rows.Add(Guid.NewGuid(), "Company 1", "[email protected]", 1);
data.Rows.Add(Guid.NewGuid(), "Company 2", "[email protected]", 1);
data.Rows.Add(Guid.NewGuid(), "Company 3", "[email protected]", 1);
using (var connection = new SqlConnection("Data Source=.;Integrated Security=true; Initial Catalog=BulkTest"))
{
await connection.OpenAsync();
using (var bulk = new Microsoft.Data.SqlClient.SqlBulkCopy(connection))
{
bulk.DestinationTableName = "Company";
bulk.ColumnMappings.Add("CompanyId", "CompanyId");
bulk.ColumnMappings.Add("CompanyName", "CompanyName");
bulk.ColumnMappings.Add("Email", "Email");
bulk.ColumnMappings.Add("CompanyType", "CompanyType");
await bulk.WriteToServerAsync(data);
}
}
Console.WriteLine("done!");
}Expected behavior
Data to be inserted without an Exception.
Further technical details
Microsoft.Data.SqlClient version: 1.1.2 also tested with 2.0.0-preview3.20122.2
.NET target: netcoreapp3.1
SQL Server version: SQL Azure, Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64)
Operating system: Windows 10 Version 10.0.18363 Build 18363
Metadata
Metadata
Assignees
Labels
No labels