google-code-export / dblinq2007

Automatically exported from code.google.com/p/dblinq2007
Other
0 stars 0 forks source link

bulkCopy.WriteToServer error when using MS SQL Server #308

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I receive the error "Unexpected existing transaction" when using BulkCopy using 
MS SQL Server 2008R2 on the line "bulkCopy.WriteToServer(dt);" in 
SQLServerVendor.cs

All is well when I change the first command of the method into:
var bulkCopy = new SqlBulkCopy((SqlConnection)transaction.Connection, 
SqlBulkCopyOptions.TableLock, (SqlTransaction)transaction);

Thus I'm using the actual transaction instead of the null.

I'm just testing dblinq so I'm not 100% sure this patch will do the trick.

Regards,
Frank

Original issue reported on code.google.com by sportfr...@gmail.com on 10 Mar 2011 at 3:15

GoogleCodeExporter commented 9 years ago
Disregard my issue.
Leaving it to a new transaction (i.e. passing null) might be better if you're 
doing a BulkInsert while you're within a transaction

Original comment by sportfr...@gmail.com on 18 Mar 2011 at 10:29

GoogleCodeExporter commented 9 years ago
dont disregard it... is actually an issue, MSDN states " if you do not specify 
a SqlTransaction object and pass a null reference, and the connection has an 
active transaction, an exception is thrown" 
(http://msdn.microsoft.com/en-us/library/tchktcdk.aspx)

first correction work fine:
var bulkCopy = new SqlBulkCopy((SqlConnection)transaction.Connection, 
SqlBulkCopyOptions.TableLock, (SqlTransaction)transaction);

thanks
mvega

Original comment by mauv...@gmail.com on 15 Apr 2011 at 10:13