Bug 22761 - SqlBulkCopy.GetColumnMetaData does not use user-provided transaction
Summary: SqlBulkCopy.GetColumnMetaData does not use user-provided transaction
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Data (show other bugs)
Version: 3.8.0
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-09-08 17:55 UTC by Michael Nero
Modified: 2018-02-22 22:36 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Michael Nero 2014-09-08 17:55:10 UTC
Overview:

SqlBulkCopy throws an exception when calling the WriteToServer(IDataReader) method if an instance is created using the constructor
   SqlBulkCopy(SqlConnection, SqlBulkCopyOptions, SqlTransaction).

The private method GetColumnMetaData correctly uses the connection provided in the ctor but not the transaction, which will throw an exception when the method executes the command it creates to get column metadata.

Steps to Reproduce:

1) Create an instance of SqlBulkCopy using the SqlBulkCopy(SqlConnection, SqlBulkCopyOptions, SqlTransaction) constructor. Ensure that the provided connection is open and the transaction is started.

2) Call the WriteToServer(IDataReader) method.

Actual Results:

A System.InvalidOperationException is thrown. The entire stack trace is below (my method calls were omitted from the stack trace)

System.InvalidOperationException: ExecuteReader requires a transaction if the command's connection is in a pending transaction.
  at System.Data.SqlClient.SqlCommand.ValidateCommand (System.String method, Boolean async) [0x00103] in C:\monosources\mono-3.6.0\mcs\class\System.Data\System.Data.SqlClient\SqlCommand.cs:778 
  at System.Data.SqlClient.SqlCommand.ExecuteReader (CommandBehavior behavior) [0x00000] in C:\monosources\mono-3.6.0\mcs\class\System.Data\System.Data.SqlClient\SqlCommand.cs:589 
  at System.Data.SqlClient.SqlCommand.ExecuteReader () [0x00000] in C:\monosources\mono-3.6.0\mcs\class\System.Data\System.Data.SqlClient\SqlCommand.cs:584 
  at (wrapper remoting-invoke-with-check) System.Data.SqlClient.SqlCommand:ExecuteReader ()
  at System.Data.SqlClient.SqlBulkCopy.GetColumnMetaData () [0x00048] in C:\monosources\mono-3.6.0\mcs\class\System.Data\System.Data.SqlClient\SqlBulkCopy.cs:183 
  at System.Data.SqlClient.SqlBulkCopy.BulkCopyToServer (System.Data.DataTable table, DataRowState state) [0x00099] in C:\monosources\mono-3.6.0\mcs\class\System.Data\System.Data.SqlClient\SqlBulkCopy.cs:392 
  at System.Data.SqlClient.SqlBulkCopy.WriteToServer (IDataReader reader) [0x00015] in C:\monosources\mono-3.6.0\mcs\class\System.Data\System.Data.SqlClient\SqlBulkCopy.cs:590

Expected Results:

No exception is thrown. I can understand if the guidance in this case is to use TransactionScope instead of an external transaction. If that's the case, it should be documented until a work-around can be implemented.
Comment 1 Marek Safar 2018-02-22 22:36:03 UTC
Mono 5.10 has significantly improved System.Data implementation which should resolve this issue. If you can still reproduce it please reopen the issue.