I am getting a SqlConnection does not support parallel transactions. exception and this answer mentions its when a connection tries to open two transactions. This is exactly what i am doing. I thought nested transactions were ok (i was using sqlite for the prototype).

How do i check if the connection is already in a transaction? I am using Microsoft SQL Server Database File.

You can check whether a transaction is already open by checking if cmd.Transaction is null.

Then wrap your code accordingly so if a transaction is already open, then the calling function owns that transaction and will commit it / roll it back appropriately.

<!-- language: lang-cs -->
//begin transaction unless one was already started
bool newTransaction = cmd.Transaction == null;
if (newTransaction) cmd.Transaction = cmd.Connection.BeginTransaction();

try {
	// do Stuff Here
	cmd.ExecuteNonQuery();
    cmd.ExecuteNonQuery();

	// commit if it's our to commit
	if (newTransaction)	cmd.Transaction.Commit();

} catch (SqlException ex) {
	if (newTransaction && cmd.Transaction != null) cmd.Transaction.Rollback();
	throw;
}

Then the parent function can pass in a command and optionally choose to begin it's own transactional block, or if not, one will be created and commited by the called function.