Subject RE: [Firebird-net-provider] FW: [firebird-support] Transactions not working as expected..
Author Chad Z. Hower
:: > public void TestLock2() {
:: > FbConnection xDB1 = new
:: > FbConnection(ADOPlus.DBConnection.ConnectionString);
:: > xDB1.Open();
:: > FbConnection xDB2 = new
:: > FbConnection(ADOPlus.DBConnection.ConnectionString);
:: > xDB2.Open();
:: >
:: > FbTransaction xTx1 = xDB1.BeginTransaction();
:: > FbCommand xCmd1 = new FbCommand("Select * from
:: \"Vendor\" where
:: > \"VendorID\" = 1", xDB1, xTx1);
:: >
:: > FbDataReader xReader1 = xCmd1.ExecuteReader();
:: > FbTransaction xTx2 = xDB2.BeginTransaction();
:: >
:: > FbCommand xCmd2 = new FbCommand("Select * from \"Vendor\"
:: > where \"VendorID\" = 1", xDB2, xTx2);
:: > FbDataReader xReader2 = xCmd2.ExecuteReader();
:: >
:: > FbCommand xCmd3 = new FbCommand("Update \"Vendor\" set
:: > \"Email\" = 'test' where \"VendorID\" = 1", xDB2, xTx2);
:: > xCmd3.ExecuteNonQuery();
:: >
:: > FbCommand xCmd4 = new FbCommand("Update \"Vendor\" set
:: > \"Email\" = 'test' where \"VendorID\" = 1", xDB1, xTx1);
:: // Locks up here
:: > xCmd4.ExecuteNonQuery();
:: >
:: > xTx2.Commit();
:: >
:: > xTx1.Commit();
:: > }
:: >
::
:: before you assign and execute xCmd4, have you tried either
:: committing or rolling back xTx1?

No. I wasn't actually trying to "perform" this code. I was trying to create
a lock error purposefully so I could trap it and identify it. I was also
trying to determine that FB works as I thought it did. In this case
shouldn't it throw a lock error? Ie cmd4 is trying to update after Cmd3
already has updated the same record. Or maybe at least on the commits?

It just locks up - I thought maybe I had a deadlock.. But I waited several
minutes and it just happily stays locked up for ever...

:: > And this one executes fine - but it should throw a lock error as I
:: > understand it:
:: >
:: > public void TestLock2() {
:: > FbConnection xDB1 = new
:: > FbConnection(ADOPlus.DBConnection.ConnectionString);
:: > xDB1.Open();
:: > FbConnection xDB2 = new
:: > FbConnection(ADOPlus.DBConnection.ConnectionString);
:: > xDB2.Open();
:: >
:: > FbTransaction xTx1 = xDB1.BeginTransaction();
:: > FbCommand xCmd1 = new FbCommand("Select * from
:: \"Vendor\" where
:: > \"VendorID\" = 1", xDB1, xTx1);
:: >
:: > FbDataReader xReader1 = xCmd1.ExecuteReader();
:: > FbTransaction xTx2 = xDB2.BeginTransaction();
:: >
:: > FbCommand xCmd2 = new FbCommand("Select * from \"Vendor\"
:: > where \"VendorID\" = 1", xDB2, xTx2);
:: > FbDataReader xReader2 = xCmd2.ExecuteReader();
:: >
:: > FbCommand xCmd3 = new FbCommand("Update \"Vendor\" set
:: > \"Email\" = 'test' where \"VendorID\" = 1", xDB2, xTx2);
:: > xCmd3.ExecuteNonQuery();
:: >
:: > xTx2.Commit();
:: >
:: > FbCommand xCmd4 = new FbCommand("Update \"Vendor\" set
:: > \"Email\" = 'test' where \"VendorID\" = 1", xDB1, xTx1);
:: > xCmd4.ExecuteNonQuery();
:: >
:: > xTx1.Commit();
:: > }
:: >
:: >
:: >
::
:: where do you expect this to throw a lock error?

I would assume on the xCmd4.ExecuteNonQuery(); as its trying to update a
record which has already been updated and committed by Cmd3.