SQL存储过程在Access中超时

时间:2013-01-20 17:23:15

标签: sql-server vba ms-access stored-procedures access-vba

从Access VBA执行时,以下SP超时。从管理控制台执行时,它工作正常。如果相关,则服务器确实具有较高的ping时间:

Dim cnn As ADODB.Connection
Dim cmd As New ADODB.Command, rs As New ADODB.Recordset, param As New ADODB.Parameter
Dim fld As ADODB.Field
Dim stMessage As String


Set cnn = New ADODB.Connection
cnn.ConnectionString = "DRIVER=SQL Server;SERVER=server01;DATABASE=db_a;Trusted_Connection=Yes"

cnn.Open cnn.ConnectionString

Set cmd = New ADODB.Command
cmd.ActiveConnection = cnn
cmd.CommandType = adCmdStoredProc

    cmd.CommandText = "we_ci_db.stprUpdateValuesInitial_A"

    Set param = cmd.CreateParameter("@DataSet", adInteger, adParamInput, , stDataSet)
    cmd.Parameters.Append param

    rs.CursorType = adOpenStatic
    rs.CursorLocation = adUseClient
    rs.LockType = adLockOptimistic

    Set rs = cmd.Execute


exit1:
Set cmd = Nothing
Set rs = Nothing
Exit Function

1 个答案:

答案 0 :(得分:3)

您可以使用CommandTimeout个对象的ADODB.Command属性设置超时:

// set a very high number of seconds before timeout
cmd.CommandTimeout = 9999999