Skip to content

SqlBulkCopy throws InvalidOperationException when using Azure SQL with managed identity on .NET 8 #30

@priyankatiwari08

Description

@priyankatiwari08

Describe the bug

When performing a SqlBulkCopy operation against Azure SQL Database using Azure AD managed identity authentication (via ActiveDirectoryManagedIdentity), the operation throws an InvalidOperationException with message "Internal connection fatal error" after copying approximately 50,000 rows.

This was working correctly in SqlClient 5.1.6. After upgrading to 5.2.1, the bulk copy operation fails intermittently.

To Reproduce

using var connection = new SqlConnection(
    "Server=myserver.database.windows.net;Database=mydb;Authentication=ActiveDirectoryManagedIdentity;");
await connection.OpenAsync();

using var bulkCopy = new SqlBulkCopy(connection)
{
    DestinationTableName = "dbo.LargeTable",
    BatchSize = 10000,
    BulkCopyTimeout = 600
};

// dataReader has ~100K rows
await bulkCopy.WriteToServerAsync(dataReader);
// Throws after ~50K rows: System.InvalidOperationException: Internal connection fatal error

Expected behavior

SqlBulkCopy.WriteToServerAsync should complete successfully for all 100K rows, as it did with SqlClient 5.1.6.

Actual behavior

Throws System.InvalidOperationException: Internal connection fatal error after ~50,000 rows are copied.

Further technical details

  • Microsoft.Data.SqlClient version: 5.2.1
  • .NET target framework: .NET 8.0
  • SQL Server version: Azure SQL Database (latest)
  • Operating system: Ubuntu 22.04 (Azure App Service Linux)

Stack trace

System.InvalidOperationException: Internal connection fatal error
   at Microsoft.Data.SqlClient.TdsParser.TryRun(...)
   at Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerInternalAsync(...)
   at Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerAsync(DbDataReader reader)

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions