Use Asynchronicity for Speed

Use Asynchronicity for Speed

If you need to run a complicated query that returns a large recordset, ADO 2.1 gives you the best of both worlds. Sometimes you just need to put a recordset into an AddItem type grid, or prepare it for a report. So, if you need to process the recordset as soon as the first record is fetched, you should start processing in the Execute_Complete event of the connection object. If you can also use a disconnected recordset, you can set the ActiveCon-nection property equal to nothing. This code might be the fastest way to process a large recordset with ADO:

 Private WithEvents m_adoConEvent As ADODB.Connection' the RS that enables the event Fetch_Complete ' to be fired off Attribute Private WithEvents m_adoRstEvent As ADODB.Recordset Private Sub GetRecordSet()	Dim sSQL As String 	'A large or complicated SQL statemtent	sSQL = "select a large complicate query"	Set m_adoConEvent = New ADODB.Connection	Set m_adoRstEvent = New ADODB.Recordset 	m_adoConEvent.Open "Connection String"	m_adoRstEvent.CursorLocation = adUseClient	Me.Caption = "Started" 	'Do something to tell the user where the process is 	'at. Have the command execute and fetch at the same 	'time without interrupting workflow.	m_adoRstEvent.Open sSQL, m_adoConEvent, _		adOpenStatc, adLockReadOnly, adCmdText _		Or adAsyncFetch Or adAsyncExecute End SubPrivate Sub m_adoConEvent_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)	Do Until pRecordset.EOF		'start processing the recordset	LoopEnd SubPrivate Sub m_adoRstEvent_FetchComplete(ByVal pError _	As ADODB.Error, adStatus As ADODB.EventStatusEnum, _	ByVal pRecordset As ADODB.Recordset)	Set pRecordset.ActiveConnection = Nothing 	'this will speed processing timeEnd SubPrivate Sub m_adoRstEvent_FetchProgress(ByVal Progress _	As Long, ByVal MaxProgress As Long, _	adStatus As ADODB.EventStatusEnum, ByVal _	pRecordset As ADODB.Recordset)	'let the user know work is happeningEnd Sub

By using both adAsyncFetch and adAsyncExecute, you can start processing even while you’re returning data.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes