Using XMLHTTP to implement remote management databases in ASP

zhaozj2021-02-16  65

A Review of Remote Database Administer has been used as a remote administrative database several years ago, the CGI-BIN module is used as a remote management database. Now, CGI-BIN is getting less and less because it is very slow, and it is difficult to maintain. In recent years, the component object model (COM) has been widely used, unfortunately, is a very troublesome thing to register a COM component on a virtual host.

On the .NET or J2EE platform, we can easily develop the N-layer web application. But for the website, we have more convenient way to remotely manage the database, such as using XMLHTTP and ADO / ADOX.

RDBA works RDBA's workflow as follows: 1 The client issues a query request to the server. 2 The server accepts and executes, and then returns the value to the client. 3 The client accepts the results from the server and displayed. RDBA depends on two technologies: 1 client and server interaction (send command, return result) channel: XMLHTTP.2 server for obtaining data intermediate layer: ADO / ADOX.

The RDBA's workflow map is as follows:

Use XMLHTTPXMLHTTP to send or accept XML information via HTTP requests. In fact, XMLHTTP has many other uses. You can use it to send commands to the server (available using XML, String, Stream, or Unsigned Array). The command can also be used as a parameter of the URL to send results information to the client (XML, String, Stream, or unsigned array) More Please refer to information:

It is very simple to use XMLHTTP in the client, just 5 steps: 1. Create an XMLHTTP object. 2. Specify methods, URLs, and verification, open XMLHTTP on the server. The open method can be "post" or "get". 3. Send Request information to the server. 4. Wait until the result is accepted from the server. 5. Release the XMLHTTP object.

XMLHTTP method: Open BSTRMETHOD, BSTRURL, Varasync, BStruser, BSTRPasswordbstrMethod: Used to open the connected HTTP method, such as GET or Postbstrull: URL on the request server, such as http: //myserver/mypath/myfile.asp. Varasync: logical type. Indicates whether it is synchronized. The default is true (call immediately returns). However, it is usually set to false to wait for the return value of the server. BSTRUSER: The authenticated username information. BSTRPASSWORD: Identified password information.

Send Varbodyvarbody: Types can be: BSTR, SafeArray Of UI1 (Unsigned Bytes), the iDispatch interface of the XML DOM object, or istream.

SetRequestHeader Bstrheader, BStrValuebstrHeader: The name of the HTTP header to be set. BSTRVALUE: The value of the http header. If you want to POST data, you can add an HTTP header to tell the reception side that is sending data: xmlhttp.setrEquestHeader "Content-Type", "Application / X-www-form-urlencoded"

XMLHTTP attribute: OnReadyStateChange: Specifies the event handler that is called when the ReadyState property is changed. ResponseBody: RESPONSERESEXSETEXT: RESPONSERESPONSETEXT: RESPONSEXSEXML in the form of a string: The following is the code snippet under XML Document Response:

Function GetResult (URLSTR) DIM XMLHTTP DIM RETSTR SET XMLHTTP = CREATEOBJECT ("MSXML2.XMLHTTTTTTP") 'Create an object on Error Resume next' error HMLHTTP.Open "Post", urlstr, false 'with "post" method to open the connection in asynchronous Send a form data XMLHTTP.SetRequestHeader "Content-Type", "Application / X-WWW-FORM-URLENCODED" XMLHTTP.SEND 'Sends an HTTP request to the server

If Err.Number = 0 THEN 'If successful retstr = xmlhttp.responsetext' Waiting from the server accepts data else retstr = "Address unnovated" 'error message end if set xmlhttp = Nothing' release object getResult = RETSTR 'Return Response to the caller The parameter of the end functionget () function is the URL to be requested, you can add sub-parameters, such as: urlstr = "Server.asp? Cmd =" ​​& cmd & "&" & db = "& db &" table = "& Table CMD: command Type, such as: Query, Modify, Delete, etc. DB: Database name table on the server: Table name

What data type is used? As mentioned above, data transmitted by XMLHTTP channels can have many types. The most used is XML DOM and String. What data type is selected depends on the needs of the program.

In order to obtain data from the server, the client and server use XML data is a good method. Because this can handle large amounts of data, request the server to add / delete / modify / query records, or sort / filter data in client.

The purpose of this article is to remotely manage the database on a virtual host, so this requires two functions: 1. Remote management database: Add / delete / modify / query remote database / table / field. 2. Data in remote management database: Add / Delete / Modify / Query Record

So here we use XMLHTTP to send / accept strings

The benefits of doing this are obvious: there is no new page without flashing.

Since it is a string, you can use "Response.Write" to return the result. Once the server response is completed, the client uses the "XMLHTTP.ResponseText" method to get the entire result and return to the caller, used to refresh the page data.

If an asynchronous method is used, the client will have a certain delay after pressing the button, and the client must wait to return data. This can be avoided if you use an asynchronous or use XML DOM.

USING Adoxado cannot be used to remotely manage the database, we can use Adox. Adox is an extension of ADO, which provides more functions for processing databases. Once authenticated by identity, and your role is a database administrator, then you can do anything through Adox.

This Sample Requests: Generates a dynamic SELECT menu to display the database name under the specified path. Generate a dynamic SELECT menu to display the table names in the selected database in the above menu. The field name is dynamically listed according to the selected database and table.

Depending on the change of the virtual directory path and the change of the SELECT, the displayed content is displayed and the refresh page does not flash.

Use scripting.filesystemObject to get the database name for a given path. Use the Adox to get the table name and field name. code show as below:

Get the table name in a database:

Sub gettables_server (dbname) DIM I DIM CATDB 'AdoDb.catalog object

Set catdb = server.createObject ("adox.catalog") 'Create an AdoDb.catalog object

ON Error ResMe next 'error handling

CATDB.ActiveConnection = "provider = microsoft.jet.Oledb.4.0;" & _ "data source =" & server.mappath (dbname) 'Open connection' If you need to add your username and password if err.number = 0 THEN ' Success' Dynamic Generation Select menu response.write " "& .Columns (i) .name &" "Display Field Name Else Response.write"

Use the samplea screenshot of gois rdba is showed asface. 2.

System required: To run this sample, the follows should be installed on your PC: Windows 98 / Me / XP / 2000, MSXML 4.0, MS Access 2000, IE 5.5 or above Install and execute: 1 Download the sample ZIP file -.. Supervisor.zip.2. unzip the file under a path in Your IIS, for example: c: / inetpub / wwwroot / supervisor. 3. Input "localhost / supervisor / supervisor.asp" in the url address on your IE, then GO.4. By a little changing, such as change the path, authorize the user, you can upload this sample source to your virtual hosting to administer your own database.There are several sample databases and two source files in the downloadable ZIP file The sample databases will automatically unzip to a "database" path under the working path, for example:. / superviosr / database.

Two source files are: Server: Server.asp Client: Supervisor.asp

Download file address: http://www.codeproject.com/UserItems/goiscode/supervisor.zip

转载请注明原文地址:https://www.9cbs.com/read-15684.html

New Post(0)