我有一个未绑定的访问表单,它使用通过存储过程从 SQL Server 2008 检索到的数据填充文本框GetIssueComponents()
。下面是这个的代码。该代码有效。我的问题是,一些 PC 将始终执行函数调用并在一秒钟内全部检索数据。但是,其他计算机将需要数十秒才能完成此操作。我们甚至有一台机器需要一两分钟!每台机器所需的时间都不同,但每台机器的时间都是一致的。
它似乎与硬件没有任何直接关系,因为许多计算机都是相同的配置,事实上,我们拥有的最差的计算机是执行该过程最快的计算机之一!所有计算机上的 ODBC 驱动程序也是相同的。所有的计算机都运行 Windows XP,我相信它们都安装了相同的补丁。不知道在哪里看,求大神帮忙!
Global adoCnn As New ADODB.Connection
Public Function ADO_ConnectionInitialize() As Boolean
Const DEBUG_THIS_PROC_NAME = "ADO_ConnectionInitialize"
Debug_Proc_Start DEBUG_THIS_PROC_NAME, True
On Error GoTo ADO_ConnectionInitialize_Error
ADO_ConnectionInitialize = False
If adoCnn.state = adStateClosed Then
adoCnn.ConnectionString = "Provider=SQLOLEDB;Data Source=10.10.10.10;Initial Catalog=" & DATABASE_NAME & ";Integrated Security=SSPI;"
adoCnn.Open
End If
ADO_ConnectionInitialize = True
ADO_ConnectionInitialize_Error:
Select Case Debug_Proc_End(DEBUG_THIS_PROC_NAME, True)
Case vbAbort
Debug.Assert False
Resume
Case vbRetry
Resume
Case vbIgnore
Resume Next
Case vbCancel
Case vbOK
Case Else
End Select
End Function
Public Function ADO_StoredProcedure(ProcName As String, Optional parameters As Variant) As ADODB.parameters
Dim comm As ADODB.Command
Dim p As Variant
Dim param As ADODB.Parameter
If ADO_ConnectionInitialize() Then
Set comm = New ADODB.Command
With comm
.ActiveConnection = adoCnn
.CommandType = adCmdStoredProc
.CommandText = ProcName
For Each p In parameters
If IsNull(p(3)) Then
Set param = .CreateParameter(p(0), p(1), p(2))
Else
Set param = .CreateParameter(p(0), p(1), p(2), p(3))
End If
.parameters.Append param
If p(2) = adParamInput Or p(2) = adParamInputOutput Then
.parameters(p(0)).value = p(4)
End If
Next
End With
comm.Execute
Set ADO_StoredProcedure = comm.parameters
Set comm = Nothing 'Memory leak if this isn't done??
End If
End Function
Public Function GetIssueComponents(ByVal issueID As Long) As String
Const DEBUG_THIS_PROC_NAME = "GetIssueComponents"
Debug_Proc_Start DEBUG_THIS_PROC_NAME
On Error GoTo GetIssueComponents_Error
Dim params As ADODB.parameters
Dim p As ADODB.Parameter
Set params = ADO_StoredProcedure("dbo.GetIssueComponents", Array( _
Array("@ReturnValue", _
ADODB.DataTypeEnum.adInteger, _
ADODB.ParameterDirectionEnum.adParamReturnValue, _
Null, _
Null), _
Array("@issueID", _
ADODB.DataTypeEnum.adInteger, _
ADODB.ParameterDirectionEnum.adParamInput, _
Null, _
issueID), _
Array("@Components", _
ADODB.DataTypeEnum.adVarChar, _
ADODB.ParameterDirectionEnum.adParamOutput, _
255, _
Null) _
))
GetIssueComponents = params("@components").value
GetIssueComponents_Error:
Select Case Debug_Proc_End(DEBUG_THIS_PROC_NAME)
Case vbAbort
Debug.Assert False
Resume
Case vbRetry
Resume
Case vbIgnore
Resume Next
Case vbCancel
Case vbOK
Case Else
End Select
End Function