我在一个非常古老的项目中遇到了问题。在长数据库进程中存在超时异常。
这是初始代码
Set objCmd = Server.CreateObject("ADODB.Command")
objCmd.ActiveConnection = Common_CnxStr
objCmd.CommandText = "Db.SP_Name"
objCmd.CommandType = adCmdStoredProc
/*some query parameters are added here*/
objCmd.Execute
这会运行90秒,然后因超时异常而失败。如何将超时增加到例如5分钟。
我尝试通过在代码中添加objCmd.CommandTimeout行来延长超时
Set objCmd = Server.CreateObject("ADODB.Command")
objCmd.CommandTimeout = 300
objCmd.ActiveConnection = Common_CnxStr
objCmd.CommandText = "Db.SP_Name"
objCmd.CommandType = adCmdStoredProc
/*some query parameters are added here*/
objCmd.Execute
但这不起作用,我在90秒后仍有异常。我甚至试图这样做
Server.ScriptTimeout = 300
Set objCmd = Server.CreateObject("ADODB.Command")
objCmd.CommandTimeout = 300
objCmd.ActiveConnection = Common_CnxStr
objCmd.ActiveConnection.CommandTimeout = 300
objCmd.CommandText = "Db.SP_Name"
objCmd.CommandType = adCmdStoredProc
/*some query parameters are added here*/
objCmd.Execute
但这并没有改变任何事情。请帮忙。
答案 0 :(得分:2)
尝试在ASP代码的开头添加:
<%
Server.ScriptTimeout = 300 ' 5 minutes!
%>
无论如何,如果是性能问题,您应该让DBA检查数据库
另见: https://technet.microsoft.com/en-us/library/bb632464.aspx