xml| Program | The Internet lets US analyze client/server applications first. In a standard client/server application, you can initialize the database connection string at the beginning of the application, which means that the customer has the right to use the database connection string, which includes the username and password. But if you do not allow this information to be sent on the network, you must send the data directly from the client to the customer without joining the database. One solution, then, is to create an ASP page on the server (called getdata.asp in this case) to receive post data in a specific format that requires an XML string to be used to create an ADO object and run a stored procedure or dynamic SQL Statement command. If the information is valid, getdata.asp executes the stored procedure and returns an XML-formatted dataset, a return value list, or an XML string of error page information. For commands that return data, the client either instantiates or returns a value or uses an error page formatted with the XML DOM (Document Object model).
OK, let's discuss how to implement this page.
The GetData.asp page first uses a DOMDocument object to hold the data sent by the client:
' Create a DOMDocument object
Set XML = Server.CreateObject ("MSXML2.") DOMDocument ")
Xml.async = False
It then loads the post data
' Load post data
Xml. Load Request
If xml.parseError.errorCode <> 0 Then
Call Responseerror ("Cannot load XML information.") "&" Description: "& Xml.parseError.reason &" <br> Line: "& Xml.parseError.Line)
End If
It can return CommandText element values and Returndata or returnvalue element values. I'll just give you the code to return the value of the CommandText element, and the rest of the code refer to the source program that I attached below.
Set N = Xml.selectsinglenode ("Command/commandtext")
If N is nothing Then
Call Responseerror ("missing <sp_name> parameter.) ")
Else Sp_name = N.text
End If
Next, you should have the page create a command object, read all the <param> elements, and create a parameter for each element in the request. Finally, let the page open a connection use the stored procedure adexecutenorecords option to execute the request.
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn. Mode=admodereadwrite
Conn.Open Application ("ConnectionString")
Set cm. Activeconnection=conn
' Return data
If not Returnsdata then
Cm. Execute
Else
Set R = Server. CreateObject ("ADODB.") Recordset ")
R.cursorlocation = adUseClient
R.open cm, adOpenStatic, adlockreadonly
End If
If the data can be returned, then the Returndata variable is true and the result dataset is returned to the client, which is still an XML document.
If Returnsdata Then
R.save Response, adPersistXML
If Err.Number <> 0 Then
Call Responseerror ("DataSet has stored Error" & "in command" & CommandText & "':" & Err.Description)
Response.End
End If
If the output parameter returns a value, the page returns an XML string containing the values. The document's root element is a <values> tag, each return value has its corresponding child element, and if any errors occur, the page formats and returns an XML string containing the error message:
Sub Responseerror (sdescription)
Response.Write "<response> <data> Error:" & sdescription & "</data> </response>"
Response.End
End Sub