ExecuteNonQuery opens a new connection

  • Thread starter Thread starter Alomgir
  • Start date Start date
A

Alomgir

Hi,

I created a new command object passing the connection and the
transaction of the existing transaction. Then I call ExecuteNonQuery.
Instead of using the same connection it opens up a new connection
causing a deadlock as both are trying to use the same resource.
Is this a correct behaviour.
Please Help.
Thanks,
Alomgir
 
This is all I did, I see no reason why a new connection is opened. When
CommitToDatabase() is called, a transaction is on and
this.sqlTransaction holds the transaction object. I am passing the same
object to the SqlCommand.


private void UpdateObjects()
{
SqlCommand command = new SqlCommand() ;
command.CommandTimeout = 900 ;
command.CommandText = "UpdateObjects_SP" ;
command.Connection = this.sqlConnection ;
command.Transaction = this.sqlTransaction ;
command.CommandType = CommandType.StoredProcedure ;
ValidateOpenConnection ( sqlConnection ) ;
command.ExecuteNonQuery ();

}

Thanks,
Alam
 
Back
Top