我試圖打開一個查詢,這是超時。我已經嘗試設置超時屬性,但它似乎並不想接受它。ADODB查詢超時
該查詢需要34秒才能執行使用MS-SQL Server管理窗口(SQL Server 2005),所以我知道我需要增加超時時間。
當前代碼:
Public Function retRecordSet(StrSQL)
Dim cmd ' as new ADODB.Command
Dim rs 'As New ADODB.Recordset
Set cmd = CreateObject("ADODB.Command")
Set rs = CreateObject("ADODB.Recordset")
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = StrSQL
cmd.CommandTimeout = 0
Set rs = cmd.Execute
Set retRecordSet = rs
End Function
我自己也嘗試設置連接本身CurrentProject.Connection.CommandTimeout = 120
的超時時間,但如果我這個命令後立即查詢值,將其保持在30
連接屬性:
Provider = Microsoft.Access.OLEDB.10.0; Persist Security Info = False; Data Source = MyServer; Integrated Security = SSPI; Initial Catalog = MyDatabase; Data Provider = SQLOLEDB.1
Data Source Object Threading Model = 1
Multiple Results = 3
Multiple Parameter Sets = False
SQL Support = 283
Catalog Location = 1
Catalog Term = database
Catalog Usage = 15
Rowset Conversions on Command = True
Extended Properties =
Cache Authentication = True
Encrypt Password =
Persist Encrypted =
Persist Security Info = False
Asynchronous Processing = 0
Connect Timeout = 600
Protection Level =
Prompt = 4
Mode =
Location =
Locale Identifier = 1033
Impersonation Level =
Window Handle =
Data Source = MyServer
User ID =
Password =
Integrated Security = SSPI
Mask Password =
Initial Catalog = MyDatabase
Lock Owner =
Bind Flags =
General Timeout = 0
Data Provider = SQLOLEDB.1
Autocommit Isolation Levels = 4096
Unique Reshape Names = False
看看這篇博客文章:http://codingjourney.blogspot.com/ 2008/11/ado-connection-timeout-command-or.html – HK1
@ HK1,你會看到我將ADODB命令的命令超時設置爲0(無限超時) – SeanC
不知道爲什麼30秒超時依然存在,奇怪。如果您調用'rs.open cmd'而不是'set rs = cmd.execute'作爲源傳入您的命令對象,會發生什麼情況。只是好奇,如果你遇到同樣的問題呢? – Fink