Help: Transaction object not associated with Connection Object

D

driss

I'm stumped. I'm using .NET 2.0 with the Enterprise Library (January
2006 edition) for communicating with my Oracle backend. I have a need
to change a set of objects' saves together, and thus figured I would
pass in the DbTransaction, but no matter what I do, and what additional
parameters I pass in, I keep getting the same Exception

{"The Transaction object is not associated with the Connection
object."}

Here's my current version of the code

-- Initiating Method --
Database db = ... [ Gets created properly ]
DbConnection con = db.CreateConnection();
DbTransaction trans;

try
{
con.Open();
trans = con.BeginTransaction();

Save2(myEntity, db, con, trans); // I'm passing in everything now,
still no luck
trans.Commit();
}
catch (Exception ex) { trans.Rollback(); }
finally { con.Close(); }

-------------------------------- Save 2 Method
--------------------------------------
DbCommand com = trans.Connection.CreateCommand(); // Next
try without the passed in DB, and then without the conn passed in.

com.CommandText = "SavePart";
com.CommandType = CommandType.StoredProcedure;
com.Connection = trans.Connection;
com.Transaction = trans;

// Add all my parameters
db.AddInParameter(com, "p_PartNumber", DbType.String,
part.PartNumber);
....
db.AddInParameter(com, "p_IsNew", DbType.Boolean,
part.IsNew);

db.ExecuteNonQuery(com); // <==== Throws the exception
----------------

I've tried
com.Connection = conn;
com.Transaction = trans;

I've tried
com = db.GetStoredProcCommand("SavePart");
com.Connection = conn;
com.Transaction = trans;

Nothing I can come up with allows me to create a Command inside Save2
that is part of a transaction from outside the method.

Any advice would be appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top