Solved

Some simple questions...

Posted on 2002-07-16
7
311 Views
Last Modified: 2007-12-19
All this time I have been writing queries in ASP pages to access data in my d/b (2-tier architecture). The question though is: If I fill my MS SQL database with stored procedures to do the same work, how do I call directly a SP from my ASP file?

E.g. I have three SPs

SP_delete_user (user_id) -> Returns 1/0
SP_add_user (name, surname, tel_no) -> Returns user_id
SP_update_user_details (name, surname, tel_no) -> Returns 1/0

how would I call them directly from my ASP ( this is again 2-tier architecture)...
0
Comment
Question by:dinosaurus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 20

Expert Comment

by:jitganguly
ID: 7156997
Follow what is described here
http://www.aspfree.com/authors/adrian/returnvalue.asp

If you happen to get errors/problems let us know

Also see for other examples

http://www.aspin.com/func/search?tree=aspin&qry=stored+procedure&cat=
0
 
LVL 12

Expert Comment

by:Wouter Boevink
ID: 7157009
include adovbs.inc or
<!--METADATA NAME="Microsoft ActiveX Data Objects 2.5 Library" TYPE="TypeLib" UUID="{00000205-0000-0010-8000-00AA006D2EA4}"-->

Function SP_add_user(strname, strsurname, strtel_no)
     Dim Conn          : Set Conn = server.CreateObject("ADODB.Connection")
     Dim cmd               : Set cmd = Server.CreateObject("ADODB.Command")
     Dim RETURN_VALUE     : RETURN_VALUE = Null

     Conn.ConnectionString = Application("Cnn_ConnectionString")
     Conn.CursorLocation = adUseClient
     Conn.Mode = adModeReadWrite
     Conn.Open

     cmd.ActiveConnection = Conn
     cmd.CommandType = adCmdStoredProc
     cmd.CommandText = "SP_add_user"

     cmd.Parameters.Append cmd.CreateParameter("RETURN_VALUE", adInteger, adParamReturnValue, 0, RETURN_VALUE)
     cmd.Parameters.Append cmd.CreateParameter("@name", adVarChar, adParamInput, 20, strname)
     cmd.Parameters.Append cmd.CreateParameter("@surname", adVarChar, adParamInput, 20, strsurname)
     cmd.Parameters.Append cmd.CreateParameter("@tel_no", adVarChar, adParamInput, 16, strtel_no)

     cmd.Execute

     SP_add_user = cmd.Parameters("RETURN_VALUE").Value

     Set cmd = Nothing
     'Conn.Close
     'Set Conn = Nothing
End Function

Dim ReturnValue
ReturnValue = SP_add_user("test","test","1234567890")
0
 
LVL 18

Expert Comment

by:bruno
ID: 7157183
wow, that looks much harder than anything i've ever done...


i've always just written a SQL string that calls the SP, and everything else on the page is the same as if it were a normal SQL string...

here is an example of a very simple one..



SQL = "SP_QUESTION "
SQL = SQL & "@ACTION = 'del', "
SQL = SQL & "@QUESTION_ID = " & QUESTION_ID


a little bigger:

SQL1 = "SP_QUESTION "
SQL1 = SQL1 & "@ACTION = 'upd', "
SQL1 = SQL1 & "@QUESTION_ID = " & QUESTION_ID & ", "
SQL1 = SQL1 & "@QUESTION = '" & QUESTION & "', "
SQL1 = SQL1 & "@SHOW_RESULTS = " & results & ", "
SQL1 = SQL1 & "@TYPE_ID = " & TYPE_ID

0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 12

Expert Comment

by:Wouter Boevink
ID: 7157272
I know it seems a lot of code, when it can be accomplished in a few lines.

Doing it this way, it's always correct you always have the right parameters and types. It's much faster.

I wrote a script which takes a stored procedure and generates the function.
0
 
LVL 11

Accepted Solution

by:
jekl2000 earned 50 total points
ID: 7157438
Might give this a try, I use it


<%dim conn
dim rs
mt=Request.Form("mt")
set conn= Server.CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB;Initial Catalog=Rettips;Data Source=GP_NT3;User ID=sa;Password=;"
set rs = conn.execute("exec sp_mtabs @mt ='"&mt&"'")
%>
0
 
LVL 2

Expert Comment

by:jsmckenzie
ID: 7157495
I don't know if those are the real names of your SPs, but you shouldn't name custom stored procedures starting with "sp_" because that's the prefix for SQL Server system stored procedures.  SQL Server thinks it's a system stored procedure and attempts to find it in the master db first.  The time it takes SQL Server to search through the master db (instead of going directly to your SP) can potentially cause a decrease in performance.
0
 

Author Comment

by:dinosaurus
ID: 7159125
I think this is the simplest way. As far as the naming conventions are concerned, no I am not using SP_ ... but thanks for this piece of very useful advice. Thank you all.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question