无法更改 Recordset 对象的 ActiveConnection 属性

Cannot change the ActiveConnection property of a Recordset object

我正在尝试打开一个记录集,以便我可以获得 RecordCount 的准确值。我有一些代码可以通过将 Recordset.OpenadOpenStaticadLockReadOnly 常量一起使用来成功地做到这一点。但是,当我使用以下代码时。

With cmd
    .ActiveConnection = db
    .CommandType = adCmdStoredProc
    .CommandText = "doGetBookingCrewDetails"

    .Parameters.Append .CreateParameter("@bookingid", adInteger, adParamInput)
    .Parameters("@bookingid") = 42943

    .Parameters.Append .CreateParameter("@starttime", adDBTimeStamp, adParamInput)
    .Parameters("@starttime") = "07/10/2016 00:00"
End With

Set rsCr = Server.CreateObject("ADODB.Recordset")
rsCr.Open cmd, db, adOpenStatic, adLockReadOnly

我收到错误

0x800a0e7b - ADODB.Recordset: Cannot change the ActiveConnection property of a Recordset object which has a Command object as its source.

上面的代码 returns 使用 Command.Execute 时的正确结果集,但是我无法指定似乎使行计数 属性 起作用的常量。

如何进行这项工作?

以下是 Open Method (ADO Recordset) 的一些要点:

The ActiveConnection property is read-only for Recordset objects whose Source property is set to a valid Command object, even if the Recordset object is not open.

the activeconnection parameter is optional.

还有

If you pass a Command object in the Source argument and also pass an ActiveConnection argument, an error occurs. The ActiveConnection property of the Command object must already be set to a valid Connection object or connection string

所以简而言之,尽量不要将 db 传递给 rsCr.open

像这样:

rsCr.Open cmd, , adOpenStatic, adLockReadOnly