Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB .net (ADO.net) Async SQL Call

Status
Not open for further replies.

MattBeas

Programmer
Nov 15, 2001
17
GB
Hello,

I need to know how to call a SQL SP asynchronously in VB.NET (ADO.NET), so my program doesn’t freeze whilst waiting . In VB6 I used to do the following:


Dim cmd as adodb.command
Dim rs as adodb.recordset

Set cmd = new adodb.command

cmd.activeconnection = cn

cmd.commandtext = “EXECUTE mysp_StoredProcedure”

set RS = cmd.execute(,,adAsyncExecute)

do while cmd.state = 4
doevents
loop


Please help.

Thanks
Matt.
 
Sonofva! I just wrote a complete code segment on how to launch your code in it's own thread, and when I hit submit, the connection died and the post was lost. nearg!!!

As the saying goes, it's easier the second time.

-Rick

----------------------
 
Code:
private delExecSP As _ExecSPDelegate

private delegate sub _ExecSPDelegate

private sub _ExecSP
  Dim cmd as adodb.command
  Dim rs as adodb.recordset

  Set cmd = new adodb.command
  cmd.activeconnection = cn
  cmd.commandtext = “EXECUTE mysp_StoredProcedure”
  set RS = cmd.execute(,,adAsyncExecute)
end sub

private sub _ExecSPComplete(ByVal ar As System.IAsyncResult)
  delExecSP.EndInvoke(ar)
end sub

Public sub ExecSP
  delExecSP = New _ExecSPDelegate(AddressOf _ExecSP)
  Dim cb As New AsyncCallback(AddressOf _ExecSPComplete)
  delExecSP.BeginInvoke(cb, del)
end sub

call the ExecSP method from your code.

-Rick

----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top