本文整理汇总了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);
}
}
}
示例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();
}
示例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);
}
}
}
示例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();
}
示例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);
}
}
}