Exception with bulk insert with remote sql server

c# sqlbulkcopy sql-server

Question

I am calling a rest full service which in turn performs bulk insert in sql server database. Every thing works fine when rest server and the database server are on same machine, but in case of remote database sever following exception is encoutered.

System.InvalidOperationException: The transaction associated with the current 
connection has completed but has not been disposed.
The transaction must be disposed before the connection can be used to
execute SQL statements.

I am using following transactions.

TransactionOptions tOptions = new TransactionOptions();
tOptions.IsolationLevel = IsolationLevel.ReadCommitted;
//This transaction is required here as it checks for all db operations.
using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew, tOptions))
{
    //DB operations....
    transactionScope.Complete();
}

Accepted Answer

Configuring the windows MSDTC service on my IIS server did the trick.

The following link shows how to configure MSDTC.

http://www.deepakkapoor.net/turn-on-msdtc-windows-7/



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why