Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
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.
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
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.
Mono 5.10 has significantly improved System.Data implementation which should resolve this issue. If you can still reproduce it please reopen the issue.