无法设置CommandTimeout值

时间:2016-10-04 14:49:31

标签: sql vba adodb oledbconnection

似乎无法将commandtimeout设置为“1秒”。看起来无处不在似乎无法弄明白。 有人可以提供一些帮助吗?这也是我的直接窗口:

Jet OLEDB:ODBC Command Time Out            1 
01             8 
05             9 
True
00             10 
00             11 
True
00             12 
00             13 
True



Sub Test()
 Dim x As Date
Dim i As Integer
x = Now

Dim objConnection As ADODB.Connection
Dim objRecordSet As ADODB.Recordset
Dim objCommand As ADODB.Command

Set objConnection = New ADODB.Connection
Set objRecordSet = New ADODB.Recordset
Set objCommand = New ADODB.Command

objConnection.CommandTimeout = 1
objConnection.Open _
    "Provider = Microsoft.Jet.OLEDB.4.0; " & _
        "Data Source = " & sDatabaseLocation


objConnection.Properties.Item(76).Value = 1
Debug.Print objConnection.Properties.Item(76).Name, objConnection.Properties.Item(76).Value
objConnection.CommandTimeout = 1
objCommand.CommandTimeout = 1

objCommand.CommandText = squery
objCommand.ActiveConnection = objConnection

Debug.Print Format(Now - x, "ss"), 8: x = Now
Set objRecordSet = objCommand.Execute
Debug.Print Format(Now - x, "ss"), 9: x = Now
Debug.Print objRecordSet.EOF
objRecordSet.Close

Debug.Print Format(Now - x, "ss"), 10: x = Now
Set objRecordSet = objConnection.Execute(squery)
Debug.Print Format(Now - x, "ss"), 11: x = Now
Debug.Print objRecordSet.EOF
objRecordSet.Close

Debug.Print Format(Now - x, "ss"), 12: x = Now
objRecordSet.Open (squery)
Debug.Print Format(Now - x, "ss"), 13: x = Now
Debug.Print objRecordSet.EOF

 objRecordSet.Close
End Sub

0 个答案:

没有答案