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
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.