J
JumpingMattFlash
I'm trying to execute two queries on a database asynchronously by using the
..NET 2.0 APM. I've created a test harness which executes two queries which
take at least ten seconds each. Using the APM I would've expected the page to
load in a little over ten seconds, but instead it takes over 30.
Here's my code for a single ASP.NET page with two gridviews on. Any pointers
as to where i may be going wrong would be appreciated:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim aResult As IAsyncResult = BeginReader()
Dim aResultTwo As IAsyncResult = BeginSecondReader()
Dim aTable As DataTable = EndReader(aResult)
GridView1.DataSource = aTable
GridView1.DataBind()
Dim aTableTwo As DataTable = EndReader(aResultTwo)
GridView2.DataSource = aTableTwo
GridView2.DataBind()
End Sub
Public Shared Function BeginReader() As IAsyncResult
Dim myConn As New SqlConnection("Data Source=(local);Initial
Catalog=MyDB;Persist Security Info=True;User
ID=test_user;Password=test_user;Async=True;")
Dim myCmd As New SqlCommand("WAITFOR DELAY '00:00:10'; SELECT TOP 10
* FROM tblUser", myConn)
myCmd.CommandType = CommandType.Text
myConn.Open()
Dim asResult As IAsyncResult = myCmd.BeginExecuteReader(Nothing,
myCmd)
Return asResult
End Function
Public Shared Function BeginSecondReader() As IAsyncResult
Dim myConn As New SqlConnection("Data Source=(local);Initial
Catalog=MyDB;Persist Security Info=True;User
ID=test_user;Password=test_user;Async=True;")
Dim myCmd As New SqlCommand("WAITFOR DELAY '00:00:10'; SELECT TOP 10
* FROM tblUser ORDER BY NEWID()", myConn)
myCmd.CommandType = CommandType.Text
myConn.Open()
Dim asResult As IAsyncResult = myCmd.BeginExecuteReader(Nothing,
myCmd)
Return asResult
End Function
Public Shared Function EndReader(ByRef asResult As IAsyncResult) As
DataTable
Dim RetTable As New DataTable
Dim myCmd As SqlCommand = CType(asResult.AsyncState, SqlCommand)
myCmd.EndExecuteReader(asResult)
myCmd.Connection.Close()
Dim myAdapter As SqlDataAdapter = New SqlDataAdapter(myCmd)
myAdapter.Fill(RetTable)
Return RetTable
End Function
..NET 2.0 APM. I've created a test harness which executes two queries which
take at least ten seconds each. Using the APM I would've expected the page to
load in a little over ten seconds, but instead it takes over 30.
Here's my code for a single ASP.NET page with two gridviews on. Any pointers
as to where i may be going wrong would be appreciated:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim aResult As IAsyncResult = BeginReader()
Dim aResultTwo As IAsyncResult = BeginSecondReader()
Dim aTable As DataTable = EndReader(aResult)
GridView1.DataSource = aTable
GridView1.DataBind()
Dim aTableTwo As DataTable = EndReader(aResultTwo)
GridView2.DataSource = aTableTwo
GridView2.DataBind()
End Sub
Public Shared Function BeginReader() As IAsyncResult
Dim myConn As New SqlConnection("Data Source=(local);Initial
Catalog=MyDB;Persist Security Info=True;User
ID=test_user;Password=test_user;Async=True;")
Dim myCmd As New SqlCommand("WAITFOR DELAY '00:00:10'; SELECT TOP 10
* FROM tblUser", myConn)
myCmd.CommandType = CommandType.Text
myConn.Open()
Dim asResult As IAsyncResult = myCmd.BeginExecuteReader(Nothing,
myCmd)
Return asResult
End Function
Public Shared Function BeginSecondReader() As IAsyncResult
Dim myConn As New SqlConnection("Data Source=(local);Initial
Catalog=MyDB;Persist Security Info=True;User
ID=test_user;Password=test_user;Async=True;")
Dim myCmd As New SqlCommand("WAITFOR DELAY '00:00:10'; SELECT TOP 10
* FROM tblUser ORDER BY NEWID()", myConn)
myCmd.CommandType = CommandType.Text
myConn.Open()
Dim asResult As IAsyncResult = myCmd.BeginExecuteReader(Nothing,
myCmd)
Return asResult
End Function
Public Shared Function EndReader(ByRef asResult As IAsyncResult) As
DataTable
Dim RetTable As New DataTable
Dim myCmd As SqlCommand = CType(asResult.AsyncState, SqlCommand)
myCmd.EndExecuteReader(asResult)
myCmd.Connection.Close()
Dim myAdapter As SqlDataAdapter = New SqlDataAdapter(myCmd)
myAdapter.Fill(RetTable)
Return RetTable
End Function