Introduction
This article explains how to create an async SqlConnection in ASP .Net 4.5 and using the SqlCommand.BeginExecuteNonQuery Method (AsyncCallback, Object).
So, let's proceed with the following procedure:
- Create an Asynchronous Page ASP .NET web page
- Create a Connection, Create a Command, Create a Parameter and Grid View binding
Creating an Asynchronous Page
Create a new project using "File" -> "New" -> "Project..." then select web "ASP .Net Web Forms Application". Name it "AsyncProgramming".

Next, create the code-behind as follows: The first step to building an asynchronous page is setting the Async attribute in the Page directive to true, as shown here:
- <%@ Page Language="C#" Async="true" %>

In the web.config file create the database. Set on the connection string: Asynchronous operation to work, the attribute Async=True; as shown here:
Now, in the code behind file AsyncSqlConnection.aspx use the following code.

- <%@ Page Language="C#" Title="Asynchronous programming" Async="true" AutoEventWireup="true"
- CodeBehind="AsyncSqlConnection.aspx.cs" Inherits="AsyncProgramming.AsyncSqlConnection" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <h3 style="font-family: Kartika; font-variant: normal; color: #0000FF; font-style: normal;">Async
- SqlConnection</h3>
- <p style="color: #FF0000">Student Details</p>
- <asp:GridView ID="StudentGridView" runat="server" BackColor="White" BorderColor="#CCCCCC"
- BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
- <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
- <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
- <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
- <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
- <SortedAscendingCellStyle BackColor="#F7F7F7" />
- <SortedAscendingHeaderStyle BackColor="#4B4B4B" />
- <SortedDescendingCellStyle BackColor="#E5E5E5" />
- <SortedDescendingHeaderStyle BackColor="#242121" />
- </asp:GridView>
- </div>
- </form>
- </body>
- </html>


Join the conversation! Your thoughts help the community grow.