468,284 Members | 1,580 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,284 developers. It's quick & easy.

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

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
0 2599

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Joe Weinstein | last post: by
15 posts views Thread by Zeng | last post: by
2 posts views Thread by Dano | last post: by
reply views Thread by DaveT | last post: by
9 posts views Thread by Andy_Khosravi | last post: by
2 posts views Thread by Christian Stooker | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.