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


C# CUBRIDConnection.SetConnectionTimeout方法代码示例

本文整理汇总了C#中CUBRID.Data.CUBRIDClient.CUBRIDConnection.SetConnectionTimeout方法的典型用法代码示例。如果您正苦于以下问题:C# CUBRIDConnection.SetConnectionTimeout方法的具体用法?C# CUBRIDConnection.SetConnectionTimeout怎么用?C# CUBRIDConnection.SetConnectionTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CUBRID.Data.CUBRIDClient.CUBRIDConnection的用法示例。


在下文中一共展示了CUBRIDConnection.SetConnectionTimeout方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Clone_Test

        public void Clone_Test()
        {
            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                LogTestStep("Clone a connection");
                conn.ConnectionString = DBHelper.connString;
                Log("change a property value of the original connection");
                conn.SetConnectionTimeout(45);
                conn.Open();

                Log("call the Clone method");
                CUBRIDConnection clonedConn = conn.Clone();
                Assert.IsTrue(clonedConn != null);

                Log("The property values are different between the original connection and the cloned connection");
                Assert.AreEqual(45, conn.ConnectionTimeout);
                Assert.AreEqual(30, clonedConn.ConnectionTimeout);

                try
                {
                    clonedConn.Open();

                    Log("Close the original connection, check the cloned connection works well");
                    conn.Close();
                    Assert.IsTrue(DBHelper.GetTableRowsCount("db_class", clonedConn) > 0);
                    clonedConn.Close();
                    LogStepPass();
                }
                catch (Exception ex)
                {
                    Log(ex.Message);
                    LogStepFail();
                }
                finally
                {
                    LogTestResult();
                    conn.Close();
                    clonedConn.Close();
                }
            }
        }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:41,代码来源:CUBRIDConnectionTest.cs

示例2: APIS_492

        public void APIS_492()
        {
            int timeout = 0;

            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                LogTestStep("Invalid timeout value");
                try
                {
                    timeout = 100;
                    conn.SetConnectionTimeout(timeout);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Assert.AreEqual("Invalid Timeout value! Expected a value between 1 and 99!", ex.Message);
                    LogStepPass();
                }

                LogTestStep("Valid timeout value, valid connection, set before open, check the timeout value is set successfuly");
                timeout = 3;
                conn.SetConnectionTimeout(timeout);
                

                //The database in the connection string does not exist
                conn.ConnectionString = "server=test-db-server;database=demodb;port=33000;user=public;password=";
                var stopwatch = new Stopwatch();
                int elapseTime = 0;
                try
                {
                    stopwatch.Start();
                    conn.Open();
                    Log("The connection should not be opened");
                    LogStepFail();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    stopwatch.Stop();
                    elapseTime = (int)stopwatch.ElapsedMilliseconds / 1000;
                    int diffTime = elapseTime - timeout;
                    Log(ex.Message);
                    Assert.AreEqual(timeout, conn.ConnectionTimeout);
                    if (diffTime >= 0 && diffTime < 10)
                    {
                        LogStepPass();
                    }
                    else
                    {
                        LogStepFail();
                    }
                }

                LogTestStep("Valid timout value, valid connection, set after open");
                try
                {
                    timeout = 20;
                    conn.SetConnectionTimeout(timeout);
                    Log("Not allowed to change the 'ConnectionTimeout' property while the connection state is!: Open.");
                    LogStepFail();
                }
                catch (Exception ex)
                {
                    Assert.AreEqual("Not allowed to change the 'ConnectionTimeout' property while the connection state is!: Open.", ex.Message);
                    LogStepPass();
                }

                LogTestResult();

            }
        }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:71,代码来源:BTSIssue.cs

示例3: Test_SetConnectionTimeout

    private static void Test_SetConnectionTimeout()
    {
        try
        {
            CUBRIDConnection conn = new CUBRIDConnection();
            conn.SetConnectionTimeout(30);
        }
        catch (Exception e)
        {
            Debug.Assert(e.Message == "The connection is not open!");
        }

        try
        {
            CUBRIDConnection conn = new CUBRIDConnection();
            conn.ConnectionString = connString;
            conn.Open();
            conn.SetConnectionTimeout(30);
            conn.Close();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }
    }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:25,代码来源:TestCUBRIDConnection.cs


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