Cannot change the ActiveConnection property of a Recordset object
<p>I'm trying to open a recordset such that I can get an accurate value for <code>RecordCount</code>. I have some code that successfully does this by using <code>Recordset.Open</code> with the <code>adOpenStatic</code> and <code>adLockReadOnly</code> constants. However, when I use the following code.</p>

<pre><code>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
</code></pre>

<p>I get the error</p>

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

<p>The above code returns the correct set of results when using <code>Command.Execute</code>, but then I can't specify the constants that seem to make the row count property work.</p>

<p>How do I make this work?</p>