ASP 3.0 Advanced Programming (45)

Source: Internet
Author: User
Tags format object dsn connect sql version window
Programming | Advanced asynchronous execution is the retrieval of data in the background and the use of the available data on a Web page before all data is returned. Although all data may be required, asynchronous work can begin processing data at least in advance. It also allows users to see something first, which makes the Web site appear to be more responsive.
Like TDC, an RDS data control can set its properties by setting parameters for object tags or by writing code. Here's an example:
<object classid= "Clsid:bd96c556-65a3-11d0-983a-00c04fc29e33"
Id= "dsoauthors" width= "0" height= "0" >
<param name= "Connect" value= "Dsn=pubs" >
<param name= "Server" value= "W2000" >
<param name= "SQL" value= "select * from Authors" >
</OBJECT>
is equivalent to:
<object classid= "Clsid:bd96c556-65a3-11d0-983a-00c04fc29e33"
Id= "dsoauthors" width= "0" height= "0" >
</OBJECT>

<script language=jscript>

function Window.onload ()
{
Dsoauthors.connect = "Dsn=pubs";
Dsoauthors.server = "W2000";
Dsoauthors.sql = "SELECT * from Authors";
Dsoauthors.refresh ();
}
</SCRIPT>
A DSN is used here for the connect parameter because it works well for the page, but it can also be any valid ADO connection string.
The URL is a new feature provided by ADO version 2.5 that allows a file to be used as a data source. The file can be in two formats: one is a Recordset saved with the Recordset.save method, and the other is an ASP page that creates a recordset and then saves it in a stream. The code is as follows:
<object classid= "Clsid:bd96c556-65a3-11d0-983a-00c04fc29e33"
Id= "dsoauthors" width= "0" height= "0" >
<param name= "URL" value= "datapage.asp" >
</OBJECT>
The file datapage.asp contains the following VBScript code:
<%
Dim Rsdata
Set rsdata = Server.CreateObject ("ADODB. Recordset ")
Rsdata.open "SELECT * from Authors", strconn
Rsdata.save Response, adPersistXML
Rsdata.close
Set Rsdata = Nothing
%>
This simply creates a recordset and then saves the recordset in XML format to the response object with the Save method. In earlier versions of ADO, only the recordset could be saved as a physical file, and the ADO 2.5 version could directly save it as a stream. The result of this ASP page is the recordset in XML format. The next chapter will look at all the topics about streaming and XML data.
The best advantage of using the URL property over the Connect and SQL properties is that the details of the connection will not appear in the Web page that the user can see. Consider the following object definition:
<object classid= "Clsid:bd96c556-65a3-11d0-983a-00c04fc29e33"
Id= "dsoauthors" width= "0" hight= "0" >
<param name= "Connect" value= "Dsn=pubs" >
<param name= "Server" value= "W2000" >
<param name= "SQL" value= "select * from Authors" >
</OBJECT>
The first line shows the details of the connection. You can see the DSN as pubs at this point, and we've selected all the columns for the authors table. This undoubtedly provides a potential path for computer hackers to enter the Web site because they know the name of the server and some details of the database. Now, consider using the URL property:
<object classid= "Clsid:bd96c556-65a3-11d0-983a-00c04fc29e33"
Id= "dsoauthors" width= "0" hight= "0" >
<param name= "URL" value= "datapage.asp" >
</OBJECT>
Now, what the user is seeing is the URL address of an ASP Web page without any details about the server and the database.
Using the Connect/sql property method, the user can see the details of the connection clearly, and the URL is the data. At this point, a security issue has been eliminated.
When you set the properties of an RDS data control in your script, you must use the Refesh method, as follows:
<script language=jscript>

function Window.onload ()
{
Dsoauthors.url= "datapage.asp";
Dosauthors.refresh ();
}
</SCRIPT>
This forces the data control to use the new property value and retrieve the data from the data provider again. In addition to the Refresh method, there are many other methods for RDS data controls, as shown in table 10-3:
Table 10-3 RDS Data Control method and description
Method
Description

Cancel
Cancel any asynchronous operation

CancelUpdate
Undo any changes to the data

CreateRecordset
Creates an empty recordset, which allows new datasets to be created locally

MoveFirst
Move to first record

MoveLast
Move to the last record

MoveNext
Move to the next record

MovePrevious
Move to previous record

Refresh
Update data from the data store

Reset
Apply Filter or Sort criteria

SubmitChanges
To send all unresolved modifications back to the data store

Later in this chapter, you see the use of most methods.
3. MSHTML Data Control
What makes Microsoft HTML (MSHTML) data controls special is that MSHTML is an integral part of IE and provides a data source based on HTML documents. Although MSHTML is not a format used for data storage in nature, mshtml may be useful if you do have many HTML pages that contain some data formats.
The code that uses this control looks like this:

[1] [2] [3] Next page



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.