Как выполнить асинхронный запрос к SQL БД используя ADO? - VB
Формулировка задачи:
Проблема выполнения асинхронного запроса к БД при доступе через ADO версии 2.5 (хранимая процедура на сервере выполняется очень долго, поэтому хочется чтобы клиент был в это время свободен). Ставил опции типа adAsyncExecute и adAsyncConnection в методе Command.Execute - не помогает. Может быть надо что-то еще указать или вообще это делается как-то по другому?
Решение задачи: «Как выполнить асинхронный запрос к SQL БД используя ADO?»
textual
Листинг программы
Dim WithEvents aConnection As ADODB.Connection
Dim bConnectionComplite As Boolean
Private Sub aConnection_ExecuteComplete(ByVal RecordsAffected As Long, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pCommand As ADODB.Command, ByVal pRecordset As ADODB.Recordset, ByVal pConnection As ADODB.Connection)
bExecComplited = True
If adStatus <> adStatusOK Then
MsgBox pError.Description & vbCrLf & pError.SQLState & vbCrLf & pError.NativeError
End If
End Sub
Public Sub AsyncExec()
Dim aCommand As ADODB.Command
Dim aRecordSet As ADODB.Recordset
Set aCommand = New ADODB.Command
With aCommand
.Name = 'Query1'
.CommandType = adCmdStoredProc
.CommandText = 'dbo.tar_CountryGetList'
.Parameters.Append .CreateParameter('return_code', adInteger, adParamReturnValue, 4)
Set .ActiveConnection = aConnection
End With
bExecComplited = False
Set aRecordSet = aCommand.Execute(, , adAsyncExecute)
While Not bExecComplited
DoEvents
Wend
End Sub