Working with a database asynchronously
This recipe walks us through the process of creating a database, populating it with data, and reading data asynchronously.
Getting ready
To step through this recipe, you will need a running Visual Studio 2012. No other prerequisites are required. The source code for this recipe can be found at BookSamples\Chapter9\Recipe3
.
How to do it...
To understand the process of creating a database, populating it with data, and reading data asynchronously, perform the following steps:
- Start Visual Studio 2012. Create a new C# Console Application project.
- In the
Program.cs
file add the followingusing
directives:using System; using System.Data; using System.Data.SqlClient; using System.IO; using System.Reflection; using System.Threading.Tasks;
- Add the following code snippet below the
Main
method:async static Task ProcessAsynchronousIO(string dbName) { try { const string connectionString = @"Data Source=(LocalDB)\v11.0;Initial Catalog=master;Integrated Security...