Thursday, April 12, 2012

Synchronous and asynchronous connection in asp.net

The application main thread is waiting for response of data base is called :"synchronous connection".In this the main thread is idle[no execution in the application] till database connectivity established. The main thread of application is not waiting for response of data base server is called "Asynchronous connection",In this case main thread will perform execution with in application with out waiting for data base response.It will improve the performance of application Asynchronous connection is recommended when the fallowed statement are not dependent on connection. 1.making connection with other data base 2.Performing remote nethod\3.Displaying form to accept data from user I will give an simple exam for how to implement the asynchronous connection using thread concept In this the asynchronous connection can be implemented to perform parallel implementation of data entry and data base connectivity.
Imports System.Data.Oledb
Imports System.Threading

public class form1

Dim cn As New OleDbConnection("provider=msdaora;user id=scott;password=tiger")
private sub connect()
cn.Open()
MsgBox("connected)
//Form1_load
Dim t As Thread
t=New Thread(address of connect)
t.start()
//save button _click
if cn.State=ConnectionState.Open
Then
Msgbox("wait for some time)
End If
End Sub

No comments:

Bel