当前位置: 首页>>代码示例>>C#>>正文


C# CUBRIDConnection.SetLockTimeout方法代码示例

本文整理汇总了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();
            }
        }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:67,代码来源:BTSIssue.cs

示例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();
                }
            }
        }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:47,代码来源:CUBRIDConnectionTest.cs


注:本文中的CUBRID.Data.CUBRIDClient.CUBRIDConnection.SetLockTimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。