0

I'm using the source code like this:

Database db1 = new Database(); //init 1 db connection
db1.BeginTransaction();

//this function used to check exist customer
//in this function, I also use Database db2 = new Database(); db2.Close();
CheckExistCustomer(); 
InsertCustomer(db1, strInsert); //this function worked correct, use db1

if(iErrorCode == ErrorStatus.SUCCESSED)
   db1.CommitTransaction(); 
else db1.RollbackTransaction();

As you see, I have 2 db connections. Can I use them? When db2.Close(), it won't affect to current db1, right? Should I use only 1 db connection (db1)?

When I run CheckExistCustomer(), the program will hang on. I don't know why. Any clue?

Please advise.

I'm very appriciated for your help.

Lang thang
  • 281
  • 1
  • 2
  • 11

1 Answers1

0

You are doing transaction management in this code. in Transaction you are performing operation on two DB, This is called Distributed Transactions, I guess BeginTransaction() method does not support Distributed Transaction, Please use TransactionScope class

TransactionScope: Avoiding Distributed Transactions

Community
  • 1
  • 1
Harikant
  • 269
  • 1
  • 6