Recommended: A simple introduction to ASP subroutines In ASP, you can call subroutines through VBScript and other ways. Example: Call the subroutine using VBScript html head %sub vbproc(num1,num2) response.write(num1*num2) end sub % /head body p You can call a program like this: /ppResult: l vbproc(3,4)%/pp or, like this: /
1. Preface
ASP (Active Server Pages) is a server-side scripting environment, which is supported by Microsoft's IIS3.0 or above. It can be used to create dynamic web pages or to generate powerful web applications. An ASP page is a file that includes HTML tags, text, and script commands. The ASP page can call ActiveX components to perform tasks such as connecting to a database or performing business calculations. ASP allows you to add interactive content to your web pages or use HTML pages to form the entire web application that uses HTML pages as your client's interface.
2. ASP model
When the browser requests the .asp file from the web server, the ASP script starts running. Then the web server calls ASP, which fully reads the requested file, executes all script commands, and transmits the web page to the browser.
ASP provides a framework for using existing scripting languages such as Microsoft VBScript and Microsoft JScript in HTML pages.
ASP provides built-in objects that make it easier for users to collect information sent through browser requests, respond to browsers, and store user information. Includes Application, Request, Response, Server, Session, and ObjectContext objects. The most commonly used are three objects, Request, Response and Server, which are used to request information from the browser, send information to the browser, and access the properties and methods of objects on the server.
III. ADO
ASP and backend database connections use Microsoft's ADO (ActiveX Data Objects), a technology that is easy to use and scalable to add database access to web pages. ADO can be used to write compact and concise scripts to connect to Open Database Connectivity (ODBC)-compatible databases and OLE DB-compatible data sources.
ADO contains 7 built-in objects, namely Connection, Command, RecordSet, Fields, Error, Parameters and Properties. Through these objects, ASP can complete all operations on the background database.
4. ASP call view and stored procedures
In general MIS applications, there will be a large number of reports. At this time, we can write corresponding views or stored procedures in the background database and use ASP to call them through ADO to complete the report work. The following is an example to illustrate the corresponding operation process.
1. Create an ODBC DSN file
Before creating a database script, you must provide a way to locate, identify and communicate with the database. The database driver uses Data Source Name (DSN) to locate and identify a specific ODBC-compatible database to pass information from the web application to the database.
2. Call SQL Server database view in ASP
The first step to accessing database information is to establish a connection with the database source. ADO provides a Connection object that can be used to establish and manage connections between an application and an ODBC database.
| The following is the quoted content: <% Set Dataconn = Server.CreateObject(ADODB.Connection) 'Create the connection object Dataconn.Open DSN=SinoTrans;SERVER=APP_SERVER; UID=sa;PWD=;APP=Microsoft (R) Developer Studio;WSID=APP_SERVER;Regional=Yes Set cmdTemp = Server.CreateObject(ADODB.Command) 'Create command object Set rst= Server.CreateObject(ADODB.Recordset) 'Create record set object cmdTemp.CommandText = Customers cmdTemp.CommandType = 2 Set cmdTemp.ActiveConnection = DataConn rst.Open cmdTemp, , 1, 3 'Generate query results %> |
At this time, Customers are view, and querying data from the view is the same as querying data from the base table.
3. Call SQL Server database stored procedures in ASP
| The following is the quoted content: <% Set Dataconn = Server.CreateObject(ADODB.Connection) 'Create the connection object Dataconn.Open DSN=SinoTrans;SERVER=APP_SERVER;UID=sa; PWD=;APP=Microsoft (R) Developer Studio;WSID=APP_SERVER;Regional=Yes Set cmdTemp = Server.CreateObject(ADODB.Command) 'Create command object Set rst = Server.CreateObject(ADODB.Recordset) 'Create record set object cmdTemp.CommandText = dbo.pd_test 'Stored procedure name cmdTemp.CommandType = 4 'The command category is 4, denoted as a stored procedure Set cmdTemp.ActiveConnection = Dataconn Set tmpParam = cmdTemp.CreateParameter(Return Value, 3, 4, 4) cmdTemp.Parameters.Append tmpParam Set tmpParam = cmdTemp.CreateParameter(@BeginDate, 135, 1, 16, riqi) 'Create an input parameter object cmdTemp.Parameters.Append tmpParam rst.Open cmdTemp, , 1, 3 'Generate query results %> |
The stored procedure called here is pd_test, which is a standard method provided in ADO, but there is a problem, that is, when there are more than two SELECT statements in the stored procedure, but it is logically impossible to execute at the same time, ADO will prompt you that there are too many SELECT statements in the stored procedure. The solution is to directly execute the stored procedure using the EXECUTE method of the CONNECTION object of ADO, as follows:
| The following is the quoted content: <% Set Dataconn = Server.CreateObject(ADODB.Connection) 'Create the connection object Dataconn.Open DSN=SinoTrans;SERVER=APP_SERVER;UID=sa;PWD=; APP=Microsoft (R) Developer Studio;WSID=APP_SERVER;Regional=Yes ss = EXECUTE dbo.pd_test & ' & riqi1 & ' Set rs = dataconn.Execute(ss) %> |
For more information on ASP and ADO usage, see the detailed reference for Microsoft ActiveX Data Objects (ADO) and Active Server Pages (ASP).
5. Call SQL Server view and stored procedure conclusion in ASP
In the development of B/S structure, we can write some commercial rules or complex queries in DBMS using stored procedures, and then call them with ADO objects in ASP to complete the traditional functions in the original C/S structure.
Share: How to write picture counters with ASP On the Internet, counters written in ASP are everywhere. I think it doesn’t make much sense to talk about ASP writing counters here. Later I thought about it and it was necessary to talk about it, because this is not just about writing counters, but about introducing ASP knowledge and application skills to everyone. The original code of the program is as follows: $#@60;%countlong=8 countlong defines the count