我有一个客户的经典 ASP 应用程序正在生成 ASP_0147 错误。我要检查的第一件事是他们正在及时关闭和释放 SQL/ADO 资源。
他们的代码具有以下模式:
Function GetXXXXRecordSet()
Set objConn = Server.CreateObject("ADODB.Connection")
With objConn
.CursorLocation = 3 ''adUseServer (default)
.ConnectionString = strConnectionString
.Open
End With
Set objCmd = Server.CreateObject("ADODB.Command")
Set objCmd.ActiveConnection = objConn
'' Build command object to call SQL stored proc, snipped for brevity
Set objRs = Server.CreateObject("ADODB.RecordSet")
objRs.Open objCmd, ,3,4 '' Cursor=adOpenStatic, Locktype=adLockBatchOptimistic
'' Return Recordset
Set GetXXXXRecordSet = objRs
If Not objCmd Is Nothing Then
objCmd.ActiveConnection = Nothing '' Should this use a Set statement?
Set objCmd = Nothing
End If
If Not ObjRs Is Nothing The Set objRs = Nothing
End Function
设置 ADO 命令的 ActiveConnection = Nothing 是否会关闭底层 SQL 连接,还是必须显式关闭?
还应该行:
objCmd.ActiveConnection = Nothing
是:
Set objCmd.ActiveConnection = Nothing
奇怪的是,第一个版本不会产生错误,这就是我问的原因。
很久没看ADO了,知识有点生疏了。