Bob
Fri Jun 20 14:22:29 CDT 2008
LOL
DW has been generating this type of atrocious code for years!
I have made many posts in this newsgroup about the evils of allowing
implicit connections to be used (which is what happens when one sets an
ActiveConnection property to a string). Here are a few of them:
<
http://groups.google.com/groups?as_q=implicit+connections&num=10&scoring=r&as_epq=&as_oq=&as_eq=&as_ugroup=&as_usubject=&as_uauthors=Bob+Barrows&lr=&as_drrb=q&as_qdr=&as_mind=1&as_minm=1&as_miny=1981&as_maxd=20&as_maxm=6&as_maxy=2008&safe=off>
shank wrote:
>>> implicit connection object (very bad). <<
> What's wrong with the connection? The code is generated by the newest
> DW CS3. I would assume they'd know the difference.
>
> thanks
>
>
> "Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message
> news:%23WSr$tv0IHA.2084@TK2MSFTNGP06.phx.gbl...
>> shank wrote:
>>> I switched to parameterized queries and now having issues with
>>> RecordCount. Regardless of the records returned, RecordCount = -1
>>> How do I get an actual count?
>>> thanks
>>>
>>> <%
>>> Dim rsProdCount__OD
>>> rsProdCount__OD = "1"
>>> If (Request("si") <> "") Then
>>> rsProdCount__OD = Request("si")
>>> End If
>>> %>
>>> <%
>>> Dim rsProdCount
>>> Dim rsProdCount_cmd
>>> Dim rsProdCount_numRows
>>>
>>> Set rsProdCount_cmd = Server.CreateObject ("ADODB.Command")
>>> rsProdCount_cmd.ActiveConnection = CONNSTRING
>>> rsProdCount_cmd.CommandText = "{call admin.stpProductCount(?)}"
>>> rsProdCount_cmd.Prepared = true
>>> rsProdCount_cmd.Parameters.Append
>>> rsProdCount_cmd.CreateParameter("param1", 200, 1, 255,
>>> rsProdCount__OD) ' adVarChar
>>> Set rsProdCount = rsProdCount_cmd.Execute
>>> rsProdCount_numRows = 0
>>> %>
>>
>> You need to change the recordset's CursorType to a cursor type that
>> supports recordcount. The default server-side forward-only cursur
>> you are getting by using the .Execute method will not support that.
>>
>> In addition, you are going to too much trouble to pass your parameter
>> values to that stored procedure, as well as using the poor coding
>> practice of using an implicit connection object (very bad). do this
>> instead: Dim cn, rs
>> set cn=createobject("adodb.connection")
>> cn.open connstring
>> set rs=createobject("adodb.recordset")
>> rs.cursorlocation=3 'adUseClient - forces a static cursor type
>> cn.DefaultDatabase = "admin"
>> cn.stpProductCount rsProdCount__OD, rs
>> 'process the recordset. don't forget to clean up.
>>
>> I would normally post a link to the relevant aspfaq article at this
>> point but I think the site may still be hacked.
>>
>> --
>> Microsoft MVP - ASP/ASP.NET
>> Please reply to the newsgroup. This email account is my spam trap so
>> I don't check it very often. If you must reply off-line, then remove
>> the "NO SPAM"
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"