Asynchronous data access in ASP.NET

D

developer

Hi All,

I am lil confused with different ways of asynchronous data access.


My understanding is that, asynchronous data access frees up a thread
instead of engaging it while a stored proc is being executed. This
makes more threads available. Is this correct or are there ay other
advantages of asynchronous data access?


My questions are:


1. I cannot set the async page directive to true as suggested in
some articles. I get an error saying incorrect page directive.


2. I can set async attribute in connection string as suggested in
few articles. I get error 'Keyword not supported.


Am I missing something to get the above errors or the articles I got
the above information from are outdated?


Here is my code. I made sense from 100 different sources before coding.

Would some one tell me if I am doing it correctly? I correctly see
deferent thread id's before and after data access.


Private Function getdata() As System.Data.SqlClient.SqlDataReader
Dim dr As System.Data.SqlClient.SqlDataReader


'code to run any sql get dr
If dr Is Nothing OrElse dr.IsClosed OrElse Not dr.HasRows Then
Return Nothing
Exit Function
End If
Return dr
End Function
Public Delegate Function AsyncDelegate() As
System.Data.SqlClient.SqlDataReader
Private Function getdataAsync() As
System.Data.SqlClient.SqlDataReader
Dim dlgt As New AsyncDelegate(AddressOf getdata)
Dim ar As IAsyncResult = dlgt.BeginInvoke(Nothing, Nothing)
'display(AppDomain.GetCurrentThreadId()) (this a thread)
Thread.Sleep(0)
Dim adr As System.Data.SqlClient.SqlDataReader =
dlgt.EndInvoke(ar)
'display(AppDomain.GetCurrentThreadId()) (this is a different
thread than the above.)
Return adr
End Function


I greatly appreciate any help
 
D

developer

I have 2.0 installed. I think 2.0 is being used to execute the code I
gave, Or else I will get an error executing it, right?
 
P

Patrice

Do you use other features from 2.0 that are working ? Have you checked that
your site uses 2.0 (you have a tab in the IIS console that allows to select
which version the site uses).

For now I 'm suspicious as the async directive doesn't seems to be
recognized. The exact error message could help. If this something else if
you write at the same place a directive name that for sure doesn't exists ?

--
Patrice

"developer" <[email protected]> a écrit dans le message de (e-mail address removed)...
I have 2.0 installed. I think 2.0 is being used to execute the code I
gave, Or else I will get an error executing it, right?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top