Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Stored Procs

    What are the different ways to fire stored procedures in a SQL 2000
    server? Which is better? I have seen simply:

    set rs = conn.execute("sproc")

    and I have also seen massive command.parameter ... bla bla ...


    @ HOTMAIL DOT COM Guest

  2. Similar Questions and Discussions

    1. Report Builder and stored Procs
      Is it possible to use a stored proc instead of query in report builder. This tool lacks any documentation that I can find. I have tried both: ...
    2. Stored Procs Compiling
      I'm using db2 8.1 with the latest service pack on Windows 2k and XP, both with latest service packs. I have Visual Studio 6 installed with latest...
    3. SQL stored procs in 8.1
      I was told ver DB2 8.1 has got SQL stored proc support (unlike earlier versions where we had only the concept of expternal stored procs which need...
    4. Help Managing Java Stored Procs
      This is sort of a followup to my last post about applicatino best practices using DB2 as a back end. Since it looks like I'm not going to get rid...
    5. Stored Outlines For Queries In PL/SQL Stored Procs
      Hi, Oracle 8.1.7.3 SunOS 5.7 I would like to know how to create stored outlines for some queries I have in stored procedures. The queries may...
  3. #2

    Default Re: Stored Procs

    > What are the different ways to fire stored procedures in a SQL 2000
    > server? Which is better?
    Depends on how you define "better"...


    Foo Man Chew Guest

  4. #3

    Default Re: Stored Procs

    Faster. Most efficient. Or even just why one is used instead of the other.

    Foo Man Chew wrote:
    >>What are the different ways to fire stored procedures in a SQL 2000
    >>server? Which is better?
    >
    >
    > Depends on how you define "better"...
    >
    >
    @ HOTMAIL DOT COM Guest

  5. #4

    Default Re: Stored Procs

    Faster. Most efficient. Or even just why one is used instead of the other.

    Foo Man Chew wrote:
    >>What are the different ways to fire stored procedures in a SQL 2000
    >>server? Which is better?
    >
    >
    > Depends on how you define "better"...
    >
    >
    @ HOTMAIL DOT COM Guest

  6. #5

    Default Re: Stored Procs

    @ HOTMAIL DOT COM" <""dk_now_48\"@ HOTMAIL DOT COM wrote:
    > What are the different ways to fire stored procedures in a SQL 2000
    > server? Which is better? I have seen simply:
    >
    > set rs = conn.execute("sproc")
    >
    > and I have also seen massive command.parameter ... bla bla ...
    There are several alternatives.

    1. Use the technique described here:
    [url]http://www.aspfaq.com/show.asp?id=2201[/url]

    Personally, I don't like this technique since:
    a. You have to worry about preventing hackers from injecting SQL into
    your code (there are ways to prevent this - see the SQL Injection FAQ at
    [url]www.sqlsecurity.com[/url])

    b. You have to correctly delimit your parameter values, just as if you
    were creating a dynamic SQL statement (actually, that is exactly what
    you are doing here). You also have to correctly handle string values
    that contain literal characters that are normally used as delimiters.
    While I've done this enough times so that it is second nature to me now,
    in the beginning this was the largest stumbling block to my learning how
    to create strings containing dynamic SQL statements.

    c. There is some performance-impairing overhead involved with both the
    concatenation of the SQL statement that ultimately runs the stored
    procedure, and the preparation of the statement on the SQL Server box,
    which happens before the statement is actually executed.

    d. It forces you to return data only by recordsets: no output or return
    values can be used with this technique. Recordsets require substantial
    resources, both on the SQL Server which has to assemble the resultset
    and pass it back to the client, and on the web server which has to
    marshal the resultset and transform it into an ADO recordset. This is a
    lot of overhead when we're talking about returning one or two values to
    the client.

    However, a lot of people do like this technique because:
    a. They have no problem knowing when and how to concatenate delimiters
    into the SQL statement, and how to handle string parameters that contain
    literal characters that are normally used as delimiters
    b. They have taken the necessary steps to prevent SQL Injection
    c. You can assign the statement to a variable and, if there's an error
    during the debug process, you can response.write the variable to see the
    actual statement being sent to the SQL Server. If the statement has been
    created correctly, you can copy and paste it from the browser window
    into Query Analyzer and further debug it
    d. They are aware of the performance hit, and consider it to be too
    minor to worry about. (To be fair, in many cases, this perfomance hit is
    relatively minor)

    The alternatives I prefer completely eliminate objection b from above.

    1. If you have output parameters, or you are interested in using the
    Return value from your procedure, use an explicit ADO Command object.
    Now, this can be tricky, especially if you do it the correct way
    (manually create the Parameters collection using CreateParameter instead
    of using Parameters.Refresh which involves an extra time-consuming trip
    to the database). However, there are many stored procedure code
    generators out there that vastly simplify this process, including the
    one I wrote which is available here:
    [url]http://www.thrasherwebdesign.com/index.asp?pi=links&hp=links.asp&c=[/url]
    &a=clear

    2. The technique I use most often is the
    "procedure-as-connection-method" technique. With ADO 2.5 and higher,
    stored procedures can be called as if they were native methods of the
    connection object, like this:
    conn.MyProcedure parmval1,...,parmvalN
    This completely avoids the need to worry about delimiters, literal or
    otherwise. Plus it turns out that this technique also causes the
    procedure to be executed in a very efficient manner on the SQL Server
    box.

    You can also use this technique if your procedure returns a recordset:
    set rs=server.createobject("adodb.recordset")
    'optionally, set the cursor location and type properties
    conn.MyProcedure parmval1,...,parmvalN, rs

    This technique does not work in ADO.Net, so if you are considering
    porting to dotnet, then you should avoid this technique.

    HTH,
    Bob Barrows


    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows Guest

  7. #6

    Default Re: Stored Procs

    > otherwise. Plus it turns out that this technique also causes the
    > procedure to be executed in a very efficient manner on the SQL Server
    > box.
    Can you elaborate? Maybe show some benchmarks?


    Foo Man Chew Guest

  8. #7

    Default Re: Stored Procs

    Foo Man Chew wrote:
    >> otherwise. Plus it turns out that this technique also causes the
    >> procedure to be executed in a very efficient manner on the SQL Server
    >> box.
    >
    > Can you elaborate? Maybe show some benchmarks?
    If you use SQL Profiler to trace your server activity during the execution
    of a procedure, you will see the intervention of several system procedures,
    sp_preparesql, etc., when using the dynamic sql and explicit Command object
    techniques, that you will not see when using the
    "procedure-as-connection-method" technique. In his book "ADO Examples and
    Best Practices", Bill Vaughn reported a substantial improvement in
    performance. This has not been borne out by my own (and others') testing: I
    saw a slight improvement. So, I will say tha it does not make a great deal
    of difference, but if you're trying to squeeze the last millisecond of
    performance out of your app ...

    Many people do not like this technique because they liken it to
    late-binding, which can be a performance killer in VB. However, in vbscript,
    late-binding is all we do (all variables being variants ... ).

    Another factor to consider is that vbscript is not a compiled language. This
    means that if you have a lot of parameters, it may take more time to compile
    and execute a bunch of CreateParameter statements than it would to use
    Parameters.Refresh even. YMMV

    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"


    Bob Barrows Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139