Quantcast
Channel: Classic ASP
Viewing all articles
Browse latest Browse all 488

ASP Classic & vbScript - Execute a SQL stored procedure with input parameters & a returned recordset

$
0
0

I am creating an ASP classic intranet page that will execute a stored procedure.  For getting the stored procedure to work I created a watered down version of the page to just pass the arguments without using an html form.  The stored procedure has input arguments and returns a recordset.  The SQL code is part of a system I do not have access to edit (but I can run the procedure in SQL Server and it runs just fine).  When I run this from my ASP page it returns a "Server Error 500 - Internal server error".  Can you tell what I am doing wrong on it?

CREATE    PROCEDURE [dbo].[ap_RF_085]
   (@Whse_Loc   as u_Whse_Loc = '',
    @Whse_Zone  as varchar(6) = '',
    @Width_Char as varchar(5) = '',
    @Height_Char as varchar(5) = '',
    @Depth_Char as varchar(5) = '',
    @Type       as char(1) = '',
    @Site       as u_Loc_Pfx --This exact parameter name is required in order for it to get populated
)AS

--Calls another stored procedure
--Populates results
--Returns SELECT statement SELECT ' Open Slots' as NoName1, substring(LongString, 1, 16) as NoName2, substring(LongString, 17, 16) as NoName3, substring(LongString, 33, 16) as NoName4, substring(LongString, 49, 16) as NoName5, substring(LongString, 65, 16) as NoName6, substring(LongString, 81, 16) as NoName7, substring(LongString, 97, 16) as NoName8, substring(LongString, 113, 16) as NoName9 FROM #Results ORDER BY Result_ID SET NOCOUNT OFF GO

Here is what the Stored Procedure returns:

NoName1NoName2NoName3NoName4NoName5NoName6NoName7NoName8NoName9
Open Slots1A011E 1A020C1A020D 1A020E1A021E 1A030B1A030D 1A030E1A031A 1A031B1A031E 1A040D1A040E 1A041B1A110A 1A110B
Open Slots1A041D 1A050B1A050D 1A050E1A051E 1A060A1A060E 1A061E1A070A 1A070B1A070E 1A071B1A071C 1A071D1A110C 1A110D

This is the ASP (vbScript) code:

<!DOCTYPE html><%@ Language=VBScript %><html><meta charset="utf-8" http-equiv="X-UA-Compatible" content="IE=11" /><head><!--#INCLUDE FILE="./SharedCode/aspConstants.asp"--><title>RF Screens</title></head><body id="rfSreens" bgcolor='#FFFFFF'><div id='wrapper'><div id='head'><%
	set conn = Server.CreateObject("ADODB.Connection")
	set cmd  = Server.CreateObject("ADODB.Command")
	set rs   = Server.CreateObject("ADODB.Recordset")
	conn.mode = 3
	conn.open "Connection String"
	set cmd.activeconnection = conn

  Dim errLoop
  Dim strError

  ON ERROR RESUME NEXT

  exeSQL = "EXEC ap_RF_085 '1A','','','','','','MZ'"  'SQL String
  rs.execute exeSQL,conn
  flds = rs.Fields.Count
  %><div><br><%response.write(flds)%><br><div class='respDiv'><table class='Response'><tr><%FOR EACH x in rs.Fields
          RESPONSE.WRITE("<th>" & x.name & "</th>")
        NEXT%></tr><%DO WHILE NOT rs.eof
        RESPONSE.WRITE("<tr>")
        FOR i = 0 to flds - 1
          RESPONSE.WRITE("<td>" & rs.Fields(i).Value & "</td>")
        NEXT
        RESPONSE.WRITE("</tr>")
        rs.MOVENEXT
      LOOP%></table></div><%
  RESPONSE.WRITE(exeSQL)

'***Error handling - vbScript***
  IF conn.Errrs.Count > 0 THEN
    FOR EACH errLoop IN conn.Errrs
      strError = "Error #" & errLoop.Number & "<br>" & _"   " & errLoop.Description & "<br>" & _"   (Source: " & errLoop.Source & ")" & "<br>" & _"   (SQL State: " & errLoop.SQLState & ")" & "<br>" & _"   (NativeError: " & errLoop.NativeError & ")" & "<br>"
      IF errLoop.HelpFile = "" THEN
          strError = strError & "  No Help file available<br><br>"
      ELSE
	  strError = strError & "   (HelpFile: " & errLoop.HelpFile & ")" & "<br>" & _"   (HelpContext: " & errLoop.HelpContext & ")<br><br>"
      END IF
      RESPONSE.WRITE("<p>" & strError & "</p>")
    NEXT
  END IF

'***Error handling - SQL***
        IF conn.Errors.Count > 0 THEN
          FOR EACH objErr IN conn.Errors
            RESPONSE.WRITE("<p>" & objErr.Description & "</p>")
          NEXT
        END IF

  Call CloseDB(rs,conn)%></div></BODY></HTML>


Viewing all articles
Browse latest Browse all 488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>