我有简单的应用程序,它有两个按钮。 第一个按钮创建事务并在提交之前保持30秒。
第二个按钮执行方法,我尝试更新同一记录。
我的观点是获取有关锁定记录的信息,但在5-6秒后抛出异常。
在PROGRESS中,会立即显示有关锁定的信息。
如何在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;
}
}
我想补充说明我的myDSN&#39;是COMMITED隔离级别。 5-6秒后出现的异常是:
&#34; System.Collections.ListDictionaryInternal pgoe1023.dll错误[HY000] [DataDirect] [ODBC进度OpenEdge有线协议驱动程序] [OPENEDGE]无法从表PUB.ad_mstr获取记录锁定。&#34;
答案 0 :(得分:0)
看起来应该在数据库服务器上设置-SQLLockWaitTimeout参数:
http://knowledgebase.progress.com/articles/Article/What-is-the-SQLLockWaitTimeout-Parameter