By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,070 Members | 1,238 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,070 IT Pros & Developers. It's quick & easy.

The transaction is either not associated with the current connection or has been completed

P: n/a
Hi

i'm using Enterprise Library for .NET Framework 2.0 january 2006 - i
really like it but, i have a problem with transactions

i'm trying to save 2 object company and user in a transaction ( when
you register on a web site)

my user object as a company object, i fill them up with info

when i save i call user.company.save first passing it a transaction
and then i do user.save passing it the transaction
the problem is that i get the error 'The transaction is either not
associated with the current connection or has been completed' , i
don't know why because t i associate the the connection and the
transaction is not completed

here is some code

user class code :

Save
{
Database db = DatabaseFactory.CreateDatabase();
using (DbConnection cnn = db.CreateConnection())
{
cnn.Open();
DbTransaction tran = cnn.BeginTransaction();
try
{
Company.Save(tran);
Add(tran)
.....
}
}
}
Add(DbTransaction tran)
{
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetStoredProcCommand(cmdname);
cmd.Connection = tran.Connection;
cmd.Transaction = tran;
......
db.ExecuteNonQuery(cmd);
....
}

Company class:
Save(tran)
{
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetStoredProcCommand(cmdName);
cmd.Connection = tran.Connection;
cmd.Transaction = tran;
....
db.ExecuteNonQuery(cmd); // <-- this is where i get the exception
....
}

any idea would help a lot
i have tried to pass as parameters the db(Database object) and / or
the cnn object
always getting the same error
I'm thinking of moving to an other DAL;

thanks

May 21 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.