Re: Please help with cmd.execute select SQL?

From: Bob Barrows [MVP] (reb01501_at_NOyahoo.SPAMcom)
Date: 03/23/05


Date: Wed, 23 Mar 2005 07:15:50 -0500

What-a-Tool wrote:
> What is the proper format for my SQL str using command.execute? Even
> though I know I have matching data in my table, I keep coming up with
> a .RecordCount of -1. What am I doing wrong?
>
> Thanks in advance :
>
> 'Create a connection object
> Set con = Server.CreateObject("ADODB.Connection")
> Set rst = Server.CreateObject("ADODB.Recordset")
> Set cmd = Server.CreateObject("ADODB.Command")
>
> strSQL = "SELECT tblUI.IPAdd FROM tblUI WHERE (tblUI.IPAdd ='?')"
> arSPrm = Array(strRemHst)
>
> con.Provider = "Microsoft.Jet.OLEDB.4.0"
> con.Open Server.MapPath("../dbs/vstr.mdb")
>
> cmd.CommandType = 1
> cmd.CommandText = strSQL
> Set cmd.ActiveConnection = con
>
> Set rst = cmd.Execute(,arSPrm)

It's got nothing to do with the use of a Command object. I think Aaron
missed the fact that you are using the Command to pass parameters to your
sql statement when he questioned your use of it.

RecordCount requires the use of an expensive cursor. The default cursor
(adOpenForwardOnly) which your code is usig, is a great, cheap cursor type
which, however, does not support RecordCount. Now some may suggest
specifying a more expensive cursor, either a client-side static cursor, or a
server-side static, keyset, or dynamic cursor. However, there is no need to
do this. Aaron's article makes the good suggestion of using GetRows, which
has several advantages:

1. By getting your data into an array, it allows you to close your recordset
and connection immediately, releasing the connection back to the connection
pool and allowing it to be re-used by the next user instead of requiring a
new connection to be open. Fewer open connections = more scalable
application.
2. Processing the data is more efficient because it can be thousands of
times faster to loop through an array than it is to loop through a recordset
3. It allows you to use Ubound to determine the number of records that were
returned

Bob Barrows

-- 
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" 


Relevant Pages

  • Re: Huge memory comsumption of ADODB Connection object
    ... Why I said the Connection ... to nothing, the memory used by my app doesn't decrease, only when I close the ... I take the same opinion as you do, if the cursor doesn't return ... resultset to client, no impact will be imposed to client. ...
    (microsoft.public.data.ado)
  • Re: VB6 ADO DB2 - Update Problem
    ... Jeweils ein Feld der beiden ... Was veranlasst Dich zu der Annahme, dass Daten eines Recordsets mit ... Man kann eine Connection auch ohne ein solches Ungetüm öffnen, ... Warum serverseitiger Cursor? ...
    (microsoft.public.de.vb.datenbank)
  • Re: psycopg, transactions and multiple cursors
    ... >> opening a connection thus the app doesn't suffer so much. ... first time a change is made to the database. ... >> what you want is a nested and not a new cursor. ... B e careful that you don;t confuse the DB API curosrs with the cursors ...
    (comp.lang.python)
  • Re: Likely KDE exploit on 4.1
    ... The cursor immediately ... An easy test is to pull the network connection, or down the net devices and see if the problem persists. ... Sometimes X/Y motion is seen backwards when the device was setup funny. ... Direct replies will be blacklisted. ...
    (comp.unix.bsd.openbsd.misc)
  • Re: Any Recordset stays empty when using SQL Native Client
    ... Even the UDL Dialogue produces parameter names with spaces, ... Additionally I eliminated the "As New" declares. ... The problem is expecting the RecordCount to always 'work'. ... You need to use a client-side cursor, or a server-side with static, keyset, ...
    (microsoft.public.vb.database.ado)