xmlHTTP technology:
----------------------------------------------------------
1. Database remote management technology
An important part of modern Internet-based WAN applications is database remote monitoring. First, let’s briefly review the development process and methods of database remote management technology on the Internet:
In the early days, the database was remotely managed by writing CGI-BIN program module. However, CGI-BIN is slow to run and is inconvenient to maintain, and is now basically deprecated.
In recent years, there have been many applications using Component Object Model (COM) and the effect is also very good. However, if you are using a third-party server (the author's website is built on a third-party virtual host), the server often does not allow users to register their own components due to confidentiality or other commercial reasons.
In recent years, the .NET platform launched by Microsoft and the J2EE platform of SUN are both very high-end database remote management and service platforms. All can provide high-quality multi-layer (n-Tier) application services.
Among them, .NET's Simple Object Access Protocol (SOAP) uses Hypertext Transfer Protocol (HTTP) and Extensible Markup Language (XML) technology to implement cross-system (such as Windows - Linux) communication service methods have been widely accepted and used by developers. Many large-scale applications, such as enterprise resource planning (ERP), are built on such large-scale platforms.
However, for small and medium-sized applications, such as the construction and maintenance of a website, such a large application platform seems to be a bit too big and the overhead is too huge.
Microsoft, which once lagged behind in Internet technology and Java technology, is ahead of the development of XML application. The XMLHTTP protocol in her XML parser (MSXML) is a very convenient and practical customer/service communication pipeline. Comprehensive use of XMLHTTP and ActiveX data objects (ActiveX Data Objects, ADO/ADOX) can easily and conveniently implement remote database management.
This article introduces how to use XMLHTTP and ADO/ADOX in a comprehensive way for remote database management.
2. Database remote management system
The task process for remote database management is:
1. The client issues query or modify instructions for database structure and data to the server.
2. The server accepts and executes relevant instructions and returns the results to the client.
3. The client accepts and displays the execution results of the instruction returned by the server.
The two main key links in realizing remote database management are:
1. The data channel for uploading instructions and downloading results between the client and the server is implemented by the XMLHTTP protocol.
2. The instruction transmission and result return between the server front-end and the database are completed by the ADO/ADOX interface that plays the role of the intermediate layer.
3. Use of XMLHTTP
As the name suggests, XMLHTTP is a hypertext transmission protocol that transmits XML format data.
In fact, the data transmission process of XMLHTTP is more flexible:
The instructions it uploads can be XML format data, a string, a stream, or an array of unsigned integers. It can also be a URL parameter.
The result it sends can be XML format data, a string, a stream, or an array of unsigned integers.
For details, please refer to the link at the end of the article.
The process of calling XMLHTTP by the client is very simple, with only 5 steps:
1. Create XMLHTTP object
2. Open the connection with the server, and define the command sending method, the service web page (URL) and request permissions, etc.
The client opens the connection to the service web page on the server through the Open command. Like ordinary HTTP directive transmission, you can use the "GET" method or the "POST" method to point to the service web page on the server.
3. Send commands.
4. Wait and receive the processing results returned by the server.
5. Release XMLHTTP object
XMLHTTP method:
Open bstrMethod, bstrUrl, varAsync, bstrUser, bstrPassword
bstrMethod: data transmission method, that is, GET or POST.
bstrUrl: The URL of the serving web page.
varAsync: Whether to execute synchronously. The default is True, which means synchronous execution, but synchronous execution can only be implemented in the DOM.
In applications, it is generally set to False, that is, asynchronous execution.
bstrUser: Username, can be omitted.
bstrPassword: User password, can be omitted.
Send varBody
varBody: instruction set. It can be XML format data, or a string, stream, or an array of unsigned integers. It can also be omitted and let the directive be substituted through the URL parameters of the Open method.
setRequestHeader bstrHeader, bstrValue
bstrHeader: HTTP header (header)
bstrValue: The value of the HTTP header
If the Open method is defined as POST, you can define the form method to upload:
"Content-Type", "application/x-www-form-urlencoded"
XMLHTTP properties:
onreadystatechange: Get the event handle that returns the result in synchronous execution mode. Can only be called in the DOM.
responseBody: The result is returned as an array of unsigned integers.
responseStream: The result is returned as an IStream stream.
responseText: The result is returned as a string.
responseXML: The result is returned as XML format data.
The following is an application example in the source program attached to this article:
Function GetResult(urlStr)
Dim xmlHttp
Dim retStr
Set xmlHttp = CreateObject("") 'Create an object
On Error Resume Next
"POST", urlStr, False 'Use POST method to open the connection and execute asynchronously.
"Content-Type", "application/x-www-form-urlencoded" 'Upload form
'Send command
If = 0 Then 'If the connection is correct
retStr = 'Waiting and getting the result string returned by the server
Else
retStr = "Url not found" 'Otherwise, an error message will be returned
End If
Set xmlHttp = nothing
GetResult = retStr ’Return to the result
End Function
The GetResult() function brings the URL parameters of a service web page, and places the uploaded command on the parameters behind the URL, such as:
urlStr = "?cmd=" & cmd & "&db=" & db & "table=" & table
cmd: Execution method, such as query, modification, deletion, etc.
db: Server database name
table: server table name
Then submit the instruction, wait and receive the returned processing result. The result is returned as a string.
Finally, the function caller processes and displays the result.