I have simple application which have two buttons. First button create transaction and hold it for 30 seconds before commit it.
Second button execute method where I tried to update the same record.
My point is to get information about locked record but exception is throwed after 5-6 seconds.
In PROGRESS, information about lock appears instantly.
How Can I achieve a similar efficiency in C#?
private void button1_Click(object sender, RoutedEventArgs e)
{
Task.Run( () =>
{
using (OdbcConnection con = new OdbcConnection("DSN=myDSN;UID=root;PWD=qweasd"))
{
OdbcCommand command = new OdbcCommand();
OdbcTransaction transaction = null;
command.Connection = con;
try
{
con.Open();
while (con.State != ConnectionState.Open)
{
Thread.Sleep(10);
}
transaction = con.BeginTransaction();
command.Connection = con;
command.Transaction = transaction;
command.CommandText = " UPDATE pub.ad_mstr SET ad_line1 = 'button3' where ad_mstr.ad_addr = 'abcdefgh' ";
command.CommandTimeout = 1;
command.ExecuteNonQuery();
for (int i = 0; i < 30; i++)
{
Thread.Sleep(1000);
}
transaction.Commit();
}
catch (Exception exc)
{
try
{
transaction.Rollback();
}
catch
{
}
}
}
//_startedTransaction1 = true;
}); /* Task.Run ( () => */
}
private void button2_Click(object sender, RoutedEventArgs e)
{
if (!_startedTransaction1)
{
Task.Run(() =>
{
using (OdbcConnection con = new OdbcConnection("DSN=myDSN;UID=root;PWD=qweasd"))
{
OdbcCommand command = new OdbcCommand();
OdbcTransaction transaction = null;
command.Connection = con;
try
{
con.Open();
while (con.State != ConnectionState.Open)
{
Thread.Sleep(10);
}
transaction = con.BeginTransaction();
command.Connection = con;
command.Transaction = transaction;
command.CommandText = " UPDATE pub.ad_mstr SET ad_name = 'button1' where ad_mstr.ad_addr = 'abcdefgh' ";
command.ExecuteNonQuery();
transaction.Commit();
}
catch (Exception exc)
{
try
{
transaction.Rollback();
}
catch
{
}
}
//_startedTransaction1 = true;
}
});
}
else
{
//_startedTransaction1 = false;
}
}
I want to add that my 'myDSN' is with COMMITED isolation level. Exception which appears after 5-6 seconds is :
"System.Collections.ListDictionaryInternal pgoe1023.dll ERROR [HY000] [DataDirect][ODBC Progress OpenEdge Wire Protocol driver][OPENEDGE]Failure getting record lock on a record from table PUB.ad_mstr."