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


C# SqlCommand.ExecuteReaderAsync方法代码示例

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


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

示例1: ExecuteCommandWithNewConnectionAsync

        private static async Task ExecuteCommandWithNewConnectionAsync(string processName, string cmdText, ICollection<string> executedProcessList)
        {
            var conn = new SqlConnection(DataTestClass.SQL2005_Northwind);

            await conn.OpenAsync();
            var cmd = new SqlCommand(cmdText, conn);


            using (SqlDataReader reader = await cmd.ExecuteReaderAsync(CommandBehavior.CloseConnection))
            {
                while (await reader.ReadAsync())
                {
                    executedProcessList.Add(processName);
                }
            }
        }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:16,代码来源:AsyncTest.cs

示例2: FailureTest

        public static void FailureTest()
        {
            string connStr = DataTestClass.SQL2005_Northwind;
            bool failure = false;
            bool taskCompleted = false;

            SqlCommand com = new SqlCommand("select * from Orders");
            SqlConnection con = new SqlConnection(connStr + ";pooling=false");
            com.Connection = con;
            con.Open();

            Task<int> nonQueryTask = com.ExecuteNonQueryAsync();
            try
            {
                com.ExecuteNonQueryAsync().Wait(TaskTimeout);
            }
            catch (AggregateException agrEx)
            {
                agrEx.Handle(
                    (ex) =>
                    {
                        Assert.True(ex is InvalidOperationException, "FAILED: Thrown exception for ExecuteNonQueryAsync was not an InvalidOperationException");
                        failure = true;
                        return true;
                    });
            }
            Assert.True(failure, "FAILED: No exception thrown after trying second ExecuteNonQueryAsync.");
            failure = false;

            taskCompleted = nonQueryTask.Wait(TaskTimeout);
            Assert.True(taskCompleted, "FAILED: ExecuteNonQueryAsync Task did not complete successfully.");

            Task<SqlDataReader> readerTask = com.ExecuteReaderAsync();
            try
            {
                com.ExecuteReaderAsync().Wait(TaskTimeout);
            }
            catch (AggregateException agrEx)
            {
                agrEx.Handle(
                    (ex) =>
                    {
                        Assert.True(ex is InvalidOperationException, "FAILED: Thrown exception for ExecuteReaderAsync was not an InvalidOperationException: " + ex);
                        failure = true;
                        return true;
                    });
            }
            Assert.True(failure, "FAILED: No exception thrown after trying second ExecuteReaderAsync.");

            taskCompleted = readerTask.Wait(TaskTimeout);
            Assert.True(taskCompleted, "FAILED: ExecuteReaderAsync Task did not complete successfully.");

            readerTask.Result.Dispose();
            con.Close();
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:55,代码来源:AsyncTest.cs

示例3: ExecuteCommandWithNewConnectionAsync

        private static async Task ExecuteCommandWithNewConnectionAsync(string processName, string cmdText, ICollection<string> executedProcessList)
        {
            var conn = new SqlConnection(DataTestUtility.TcpConnStr);

            await conn.OpenAsync();
            var cmd = new SqlCommand(cmdText, conn);

            using (SqlDataReader reader = await cmd.ExecuteReaderAsync())
            {
                while (await reader.ReadAsync())
                {
                    executedProcessList.Add(processName);
                }
            }
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:15,代码来源:DDAsyncTest.cs

示例4: ExecuteTest

        public static void ExecuteTest()
        {
            SqlCommand com = new SqlCommand("select * from Orders");
            SqlConnection con = new SqlConnection(DataTestUtility.TcpConnStr);

            com.Connection = con;

            con.Open();

            Task<SqlDataReader> readerTask = com.ExecuteReaderAsync();
            bool taskCompleted = readerTask.Wait(TaskTimeout);
            Assert.True(taskCompleted, "FAILED: ExecuteReaderAsync Task did not complete successfully.");

            SqlDataReader reader = readerTask.Result;

            int rows;
            for (rows = 0; reader.Read(); rows++) ;

            Assert.True(rows == 830, string.Format("FAILED: ExecuteTest reader had wrong number of rows. Expected: {0}. Actual: {1}", 830, rows));

            reader.Dispose();
            con.Close();
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:23,代码来源:AsyncTest.cs

示例5: ExecuteCommandWithSharedConnectionAsync

        private static async Task ExecuteCommandWithSharedConnectionAsync(SqlConnection conn, string processName, string cmdText, ICollection<string> executedProcessList)
        {
            var cmd = new SqlCommand(cmdText, conn);

            using (SqlDataReader reader = await cmd.ExecuteReaderAsync(CommandBehavior.CloseConnection))
            {
                while (await reader.ReadAsync())
                {
                    executedProcessList.Add(processName);
                }
            }
        }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:12,代码来源:AsyncTest.cs


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