简体   繁体   中英

Query timeout error Excel VBA

I'm trying to run a SQL Server query via Excel VBA which gives me below error. I have tested this query in SQL Server Management Studio & it working perfectly fine. It takes about 4 mins to run in SSMS, but fails via VBA. I have already tried increasing the timeout up to 600 secs & setting it to zero as well.

Surprising part is if I debug my VBA & copy the script from it (since it's generated @ runtime based on different values) even that run perfectly after pasting in SQL Server Management Studio?

在此处输入图片说明

What am I missing here? Any pointers would be highly appreciated...

PS: if I run another query with same piece of code, it runs correctly!

Using: DBConn.CommandTimeout = 0 solved the problem for queries that take longer for execution & cannot be optimised further.

Thx a ton @Vityata for pointing me to right direction =)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM