---
title: "ADO.Net Transaction when Command's transaction is not set"  
description: "ADO.Net Transaction when Command's transaction is not set"  
author: "Anonymous User"  
published: 2013-06-19  
updated: 2013-06-19  
canonical: https://www.mindstick.com/forum/1219/ado-dot-net-transaction-when-command-s-transaction-is-not-set  
category: "ado.net"  
tags: ["ado.net"]  
reading_time: 1 minute  

---

# ADO.Net Transaction when Command's transaction is not set

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances), \
I came across a [sample](https://www.mindstick.com/news/2174/mars-mission-by-nasa-prepares-for-tests) on [ADO.Net](https://www.mindstick.com/articles/804/connection-pooling-in-ado-dot-net), where a [transaction](https://www.mindstick.com/blog/175/transactions-in-database) was being done without setting the [command](https://www.mindstick.com/blog/178/synchronous-and-asynchronous-command-execution-in-c-sharp-dot-net)'s transaction [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) as in [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) below.\
Is this possible Or one needs to explicitly set the command's transaction property?\
**// Start a [local](https://www.mindstick.com/forum/546/how-to-create-local-user-in-windows-8) transaction.****SqlTransaction sqlTran = connection.BeginTransaction();****\****// Enlist a command in the current transaction.** **[SqlCommand](https://www.mindstick.com/forum/91/difference-between-sqlcommand-and-sqlcommandbuilder) command = connection.CreateCommand();****-----****-----****sqlTran.Commit()****\**Any help on above is really appreciated.

## Replies

### Reply by Sumit Kesarwani

Hi Tanuj,\
That should throw a runtime exception. That is, if you have an active transaction on a SqlConnection and do not assign a reference to the corresponding SqlTransaction to the SqlCommand.Transaction property and attempt to execute the command, you should get an exception.\
In short, set the Transaction property explicitly when executing a command on a connection with an active transaction.\


---

Original Source: https://www.mindstick.com/forum/1219/ado-dot-net-transaction-when-command-s-transaction-is-not-set

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
