本文整理汇总了C#中CUBRID.Data.CUBRIDClient.CUBRIDConnection.SetLockTimeout方法的典型用法代码示例。如果您正苦于以下问题:C# CUBRIDConnection.SetLockTimeout方法的具体用法?C# CUBRIDConnection.SetLockTimeout怎么用?C# CUBRIDConnection.SetLockTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUBRID.Data.CUBRIDClient.CUBRIDConnection
的用法示例。
在下文中一共展示了CUBRIDConnection.SetLockTimeout方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: APIS_485
public void APIS_485()
{
LogTestStep("Test the lockTimeout is set successfully");
CUBRIDConnection conn = new CUBRIDConnection();
conn.ConnectionString = DBHelper.connString;
Assert.AreEqual(-1, conn.LockTimeout);
conn.Open();
int timeout = 20;
conn.SetLockTimeout(timeout);
Assert.AreEqual(timeout, conn.LockTimeout);
DBHelper.ExecuteSQL("drop table if exists t", conn);
DBHelper.ExecuteSQL("create table t(id integer)", conn);
DBHelper.ExecuteSQL("insert into t values (1)", conn);
conn.SetAutoCommit(false);
CUBRIDConnection conn2 = null;
double elapseTime = 0;
var stopwatch = new Stopwatch();
try
{
Thread thread2 = new Thread(delegate()
{
conn2 = new CUBRIDConnection();
conn2.ConnectionString = DBHelper.connString;
conn2.Open();
conn2.SetAutoCommit(false);
conn2.BeginTransaction();
DBHelper.ExecuteSQL("update t set id=2", conn2);
});
conn.BeginTransaction();
thread2.Start();
Thread.Sleep(5000);
stopwatch.Start();
DBHelper.ExecuteSQL("update t set id=3", conn);
thread2.Join();
}
catch (Exception ex)
{
stopwatch.Stop();
elapseTime = (double)stopwatch.ElapsedMilliseconds / 1000;
double diffTime = elapseTime - (double)(timeout / 1000);
Console.WriteLine("different time = " + stopwatch.ElapsedMilliseconds);
Console.WriteLine("different time = " + diffTime);
Log(ex.Message);
Assert.AreEqual(timeout, conn.LockTimeout);
if (diffTime >= 0 && diffTime < 10)
{
LogStepPass();
}
else
{
LogStepFail();
}
}
finally
{
LogTestResult();
//DBHelper.ExecuteSQL("drop table t", conn);
conn.Close();
conn2.Close();
}
}
示例2: SetLockTimeOut_WithParam_Test
public void SetLockTimeOut_WithParam_Test()
{
int timeout;
using (CUBRIDConnection conn = new CUBRIDConnection())
{
conn.ConnectionString = DBHelper.connString;
LogTestStep("connection is not open");
try
{
timeout = 2;
conn.SetLockTimeout(timeout);
}
catch (Exception ex)
{
Assert.AreEqual("The connection is not open!", ex.Message);
LogStepPass();
}
conn.Close();
LogTestStep("Valid timout value, and connection is open");
timeout = 35;
conn.Open();
conn.SetLockTimeout(35);
Assert.AreEqual(35, conn.LockTimeout);
LogStepPass();
LogTestStep("Valid timout value, change the lock timeout");
try
{
Assert.AreEqual(35, conn.LockTimeout);
conn.SetLockTimeout(40);
Assert.AreEqual(40, conn.LockTimeout);
LogStepPass();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
//Assert.AreEqual("Not allowed to change the 'LockTimeout' property while the connection state is!: Open.", ex.Message);
LogStepFail();
}
finally
{
LogTestResult();
}
}
}