2013-07-10 60 views
3

我試圖打開一個查詢,這是超時。我已經嘗試設置超時屬性,但它似乎並不想接受它。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 
+3

看看這篇博客文章:http://codingjourney.blogspot.com/ 2008/11/ado-connection-timeout-command-or.html – HK1

+1

@ HK1,你會看到我將ADODB命令的命令超時設置爲0(無限超時) – SeanC

+0

不知道爲什麼30秒超時依然存在,奇怪。如果您調用'rs.open cmd'而不是'set rs = cmd.execute'作爲源傳入您的命令對象,會發生什麼情況。只是好奇,如果你遇到同樣的問題呢? – Fink

回答

0

對於OLEDB,你不需要指定連接上的timout: -

提供商= Microsoft.Access.OLEDB.10.0;堅持安全信息= FALSE;數據來源 = MyServer的;集成安全性= SSPI;初始 目錄= MyDatabase的;數據提供商= SQLOLEDB.1;連接超時= 30

12

不知道,如果你已經拿到過這個問題,但我有同樣的問題。 我正在用Recordset.Open SQL_String,Connection來做它。

而在這之前我只設置超時屬性,而不是在記錄或命令,但Connection對象:

Connection.CommandTimeout = 0