Wednesday, January 9, 2013

ExecuteNonQuery requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized

ExecuteNonQuery requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized

While using transaction in Asp.net/C# I got above error.

To solve this error I simply added Transaction object in SqlCommand like below
SqlTransaction Transaction;
conn.Open();
Transaction = conn.BeginTransaction(); 
SqlCommand cmd = new SqlCommand(sql, conn, Transaction);

Submit this story to DotNetKicks

1 comments:

Magician Ashwini Sh. May 27, 2013 at 5:25 PM  

WOW SIRJI ITS AMZING AND GRESAT.
VERY SHORT TRICK.
WOW......................................................
I AM REALLY IMPRESSED