home *** CD-ROM | disk | FTP | other *** search
/ Chip 2009 November / Chip_2009.11_CD.iso / I386 / IIS6.CAB / IIS_StoredProcedures_VBScript.asp < prev    next >
Encoding:
Text File  |  2001-10-04  |  2.2 KB  |  79 lines

  1. <%     @ LANGUAGE="VBSCRIPT"         %>
  2. <%    Option Explicit                %>
  3.  
  4. <!--METADATA TYPE="typelib" uuid="00000206-0000-0010-8000-00AA006D2EA4" -->
  5. <%' This example can be used to call the ByRoyalty stored procedure 
  6. ' installed with the PUBS database with Microsoft SQL Server.
  7.  
  8. ' This sample assumes that SQL Server is running on the local machine
  9.  
  10. ' SQL needs to know the name of the server.  Since IISHelp calls this file with 
  11. ' "http://localhost...", simply using Request.ServerVariables("SERVER_NAME")
  12. ' will not work because it returns the name "localhost" instead of the machine name.
  13. ' SQL doesn't recognise "localhost" as itself for security reasons.
  14. ' This script uses an If... Then statement to call itself once the user has specified the server name.
  15. %>
  16.  
  17.  
  18. <HTML>
  19.     <HEAD>
  20.         <TITLE>Using Stored Procedures</TITLE>
  21.     </HEAD>
  22.  
  23.     <BODY bgcolor="white" topmargin="10" leftmargin="10">
  24.         
  25.         <!-- Display Header -->
  26.  
  27.         <font size="4" face="Arial, Helvetica">
  28.         <b>Using Stored Procedures</b></font><p>   
  29.  
  30.         <%
  31.         if ("" = Request.Form("srvname")) then
  32.             Response.Write "Please enter the name of your SQL server:<BR>"
  33.             %>
  34.             <FORM method="POST" action="StoredProcedures_VBScript.asp">
  35.             <INPUT name=srvname type=text>
  36.             <INPUT type=submit value="Enter">
  37.             <%
  38.         else
  39.             Dim oConn    
  40.             Dim strConn    
  41.             Dim oCmd    
  42.             Dim oRs        
  43.  
  44.             Set oConn = Server.CreateObject("ADODB.Connection")
  45.             Set oCmd = Server.CreateObject("ADODB.Command")
  46.  
  47.             
  48.             ' Open ADO Connection using account "sa"
  49.             ' and blank password
  50.              
  51.             strConn="Provider=SQLOLEDB;User ID=sa;Initial Catalog=pubs;Data Source="& Request.Form("srvname")
  52.             oConn.Open strConn
  53.             Set oCmd.ActiveConnection = oConn
  54.  
  55.  
  56.             ' Setup Call to Stored Procedure and append parameters
  57.  
  58.             oCmd.CommandText = "{call byroyalty(?)}"
  59.             oCmd.Parameters.Append oCmd.CreateParameter("@Percentage", adInteger, adParamInput)
  60.  
  61.             
  62.             ' Assign value to input parameter
  63.  
  64.             oCmd("@Percentage") = 75
  65.  
  66.  
  67.             ' Fire the Stored Proc and assign resulting recordset
  68.             ' to our previously created object variable
  69.                     
  70.             Set oRs = oCmd.Execute            
  71.             %>
  72.  
  73.             Author ID = <% Response.Write oRs("au_id") %><BR>
  74.         <%
  75.         end if
  76.         %>
  77.     </BODY>
  78. </HTML>
  79.