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

SqlBulkCopy is not working with active Sensitivity Classification on Column #559

Closed
schwarzr opened this issue May 12, 2020 · 2 comments · Fixed by #568
Closed

SqlBulkCopy is not working with active Sensitivity Classification on Column #559

schwarzr opened this issue May 12, 2020 · 2 comments · Fixed by #568
Assignees
Labels
🐛 Bug! Issues that are bugs in the drivers we maintain.

Comments

@schwarzr
Copy link

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", "sample1@contoso.com", 1);
    data.Rows.Add(Guid.NewGuid(), "Company 2", "sample2@contoso.com", 1);
    data.Rows.Add(Guid.NewGuid(), "Company 3", "sample3@contoso.com", 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

@DavoudEshtehari
Copy link
Contributor

Hi @schwarzr,

Thank you for reporting the issue with comprehensive information to reproduce.
The error happens with WriteToServer and WriteToServerAsync at native and managed parts.

@DavoudEshtehari DavoudEshtehari added the 🐛 Bug! Issues that are bugs in the drivers we maintain. label May 12, 2020
@DavoudEshtehari DavoudEshtehari pinned this issue May 12, 2020
@DavoudEshtehari DavoudEshtehari unpinned this issue May 12, 2020
@simader
Copy link

simader commented May 19, 2020

Any idea, when this will be fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug! Issues that are bugs in the drivers we maintain.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants