VB 6 data access affected by MsgBox

Go To StackoverFlow.com

3

This problem is beyond weird. I am submitting it in the hope that someone may have seen it before and knows a fix.

Environment VB6, SQL 2005, Citrix XenApp 6.5. This behavior only appears when running from a Citrix client.

The context:

Main .bas module loads and in the Main sub it calls SQL server (2005) using ADO recordsets to load data. When run from the console, the app loads and displays in 1 or 2 seconds. When called from a Citrix client, it slows down by a factor of at least 30. However, if we place a MsgBox

i.e.

MsgBox "Test message..."

in the code of the Main sub, it loads in 1 to 2 seconds just like the load from the console. The MsgBox must be placed after loading the MDI form that acts as the visual backdrop for the app. If placed before the MDI is loaded, it does not fix the problem.

By placing debugging messages in the caption of the MDI form, we have detected the time it takes to walk through a recordset is where all the time is being added in.

The question is how can a MsgBox statement affect the access speed of a recordset. Sounds very odd, but with the MsgBox statement: fast, without it: deadly slow.

A reduced version of the Sub Main is below with the magic MsgBox indicated.

****************************************************************
*
****************************************************************
Sub Main()
On Error GoTo errHandler



'CSR 527
If Not ReadIniFiles Then
    MsgBox "Error reading ini files...contact systems.", vbExclamation
    End
End If

g_SecurityInClause = "YES"

If Not SetSecurity Then
    MsgBox "Unable to acquire your authorization credentials. Exiting..."
    Exit Sub
End If

Set cn = New Connection
With cn
 ' .ConnectionTimeout = 30
  .ConnectionString = CONNECTION_STRING
  .Open 'Options:=adAsyncConnect
End With

App.HelpFile = App.path & "\xx.chm"

g_bExiting = False

frmMain.MousePointer = vbHourglass
DoEvents
frmMain.Show

MsgBox "test"  <== PLACING THIS MSGBOX HERE SPEEDS UP APP BY A FACTOR OF AT LEAST 30
                   IF IT IS ABOVE frmMain.Show IT HAS NO EFFECT

'assign connection string and record source to ado controls
'PLOG 74

Load frmA


frmA.Adodc1.ConnectionString = CONNECTION_STRING
frmA.Adodc2.ConnectionString = CONNECTION_STRING
frmA.Adodc3.ConnectionString = CONNECTION_STRING

'timeouts for Phoenix
frmA.Adodc1.CommandTimeout = 300
frmA.Adodc2.CommandTimeout = 500
frmA.Adodc3.CommandTimeout = 500

frmA.Adodc1.RecordSource = "select some stuff"
frmA.Adodc2.RecordSource = "select some stuff"
frmA.Adodc3.RecordSource = "select some stuff"

frmA.Adodc1.Refresh
frmA.Adodc2.Refresh
frmA.Adodc3.Refresh

LoadMinorCodes
DetermineDeleteAccess
LoadStates

frmMain.MousePointer = vbNormal
frmStartBoard.Show


Exit Sub


errHandler:
MsgBox Err.Number & " " & Err.Description & " Main"


End Sub
2012-04-04 21:47
by Richard
Does replacing the test msgbox with a DoEvents get the same results for you - jac 2012-04-05 03:48
Why do you use ADODC (ADO Data Control) to access your data? You can access your data with ADODB from anywhere without using any form or control - Martin 2012-04-05 08:43
What happens if you move that MsgBox after Load frmA - tcarvin 2012-04-05 15:34
Thank you! The DoEvents did it. As far as the ADODC...this is all legacy stuff, we are replacing this old warhorse with C# in the near future so have not refactored it. Thanks again - Richard 2012-04-05 18:52


0

From jac's comment, to add a DoEvents, and from the fact that it worked for you, it must have been only a race condition problem. It was probably waiting for the database to connect before it showed the form. Adding the doEvents changed that order.

2013-08-02 13:08
by M Granja
Ads