Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Tue, 11 Dec 2007 02:01:00 -0800,    group: microsoft.public.dotnet.datatools        back       


Asynchronous Programming Model & ADO.NET   
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
-- 
=============
VB .NET Developer
http://www.rocketscience.uk.com
http://info.i-snapshot.com
date: Tue, 11 Dec 2007 02:01:00 -0800   author:   JumpingMattFlash

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us