F
fredd00
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
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