Transferring data between a server and a customer

Source: Internet
Author: User
Server | data


At the beginning of this chapter, we have provided you with a block diagram of RDS, determining which components are clients, and which components are server-side. In the previous section, you focused on client components, data controls, because they are the easiest way to use RDS. They allow seamless transfer of data from the server to the client, as well as an easy way to process data on a Web page. To get the data on the server, just set a few properties, and calling one or two methods is sufficient.
The problem with data controls is that they have a relatively limited ability to access data, i.e., lack of flexibility. For RDS data controls, the details of the connection and the query must be specified through parameters such as connect i o N and SQL, which limits us to the database and simple queries. In addition, users can see these parameters, so there is a potential security vulnerability when using the RDS data control. Although the property U R solves the problem partly by specifying the actual data source rather than the location where the data is obtained, there are still drawbacks. The user can still get u R L and read the data directly, which is not what we want.
The introduction of IE 5.0 makes it easier to access x m l data, so the X m L data will certainly be widely used later. As with the U R L property of the RDS data control, users can also read data directly because the name of the data source is visible to them.
Therefore, some of the following issues need to be considered.
? A secure method is needed to retrieve server-side data and use them on the client.
? You need a way to update your data.
? No loss of flexibility.
The solution to these problems is to use components. Component allows you to encapsulate access to all data, including data sources, to ensure that data is displayed only on Web pages. You can hide the details of connections because they are not exposed to the user within the component, so security is not compromised. You can also create your own components to update the data so that the spirit that can update the data is preserved
Activity.
Additionally, security is added because the registry needs to be modified before the client accesses the server component. This ensures that only the required components are created, that users are prevented from uploading components, and then access them from the server. You'll see how to modify the registry later.
10.3.1 Server-based components
It's not a big deal to discuss how to create a component here, because it's covered in sections later in this book, and there are some very simple code for server components. This helps illustrate the RDS example that will be used.
First, the component starts with a constant that defines the details of the connection, and in this case the SQL Server and P u B databases.

The first method is then created to provide a recordset to the client Web page. This is a standard Visual Basic function that returns a standard a D o R e c o RDS e-T object.


Here are two important places to pay attention to. The first is to set the C u r S o r l o c a t i o n to a D u S e c l e N T to ensure that the client cursor engine is used. This is necessary for disconnected recordsets. The 2nd need to note is the following line of code:

"Disconnect" the recordset from the server side and securely return the recordset to the client.
The second method of the component updates the server with our modifications to the disconnected recordset. It takes a recordset parameter, reconnect to the data store, and then issue the U P d a T e B a T C h command. This sends all batch modifications to the server.

This is the entire contents of this component. Obviously, we're simplifying it so we can quickly show what it contains, but there's really no limit to what can be put in the component. In chapters 1th 3 to 1th 8, you will see more examples of how and why to do so.
10.3.2 DataSpace Object
The D a t a S p a C e object is the client object responsible for communicating with the server. Its task is to provide a way to create server-side components from the client, while allowing data to be transferred between the client and the server.
It may sound complicated, but it's actually very simple. Create a D a t a C e object on the Web page and use the D a t a s p a C e object to create the server-side component.
There are two ways to create a C-e object of a D a t a S p. The first method uses the object> tag:

This is almost the same as the way in which other client RDS components were created in the past, and the only difference is Class I D.
The second method is to use scripting code to create the D a t a S p a C e object. The following code shows how to create a D a T s p a c e object with J s C R i p T.

The main difference between the two approaches is that when using the object> tag, the D a t a S p a C e object is created only when the page is loaded. Using scripting means that when the script runs, it creates the D a T S p a C e object. If you want to delay object creation to make the page load faster, you can use scripting techniques.
Create a server component using the D a T S p a C e object
Once you have created the D a T S p a C e object, you can create a server-side object using the C R e a T-e-object method.

P ro g I D is the object that you want to create I d,connect i o n is the Web server's U R L address. For example, suppose you have a database that provides p u B s data
Visual Basic components, as shown in Figure 1 0-1 2.

Here, p ro g I D should be WR o x P u b S. P u b S. The following is illustrated in detail in a complete example.
(1) Creating components and fetching data
Suppose P U B S class has two methods, G e t a u t h o R S and S e t a u t h o R S, used to read and update A u t h o r S table. Before you create a component, you create an RDS data control to hold and bind the data. Note that there is no connection detail here.

You can then create the server component using the following client script code:

This creates an instance of the D a T S p a C e object, and then creates the server-side object using the C R e a T E-object method. Here, you specify the name of the object and the Web server. In this example, the name of the Web server is set to L o c a l h o s T, and it should be the actual name of the server. This is not a security issue because the user is connecting to the Web site.
Now, the variable o b J p u b S is wr o x P u b S. An instance of a P U B object that can call its methods as you would with other objects.

Call the G e t a u t h o R S method to return a disconnected recordset. All you need to do now is use this recordset, so you can use one of the RDS data controls (created with the < OBJECT > tag) to hold the recordset and bind the data. Use the SourceRecordset property of the data control to receive a recordset obtained from the assembly.

In this case, the data control behaves as if it were getting the data, and the only difference is that we have provided the data from the component.
(2) Update data using components
Readers may want to know how to update data when using server-side components? You cannot use a data control s u B m i t C h a n g e s method, because the data control does not have the details of the connection, so you do not know where the data comes from. Since the recordset is a standard disconnected recordset and its data is provided by the server component, does the component seem to know the source of the data? Yes. It is therefore necessary to pass this disconnected recordset to the server component, which performs a batch update.
To do this, first remove the recordset from the data control and pass it as a parameter to the server object's method.

Actually it's quite simple.
10.3.3 advantages of using server-side components
So what is the biggest feature of server-side components? Take a look at its advantages:
? The connection details are not visible to the user and provide us with a more secure system. Also, components must be registered, which is an additional security restriction.
? You can create components in any language that is compatible with C O m. The reason for using Visual Basic in the example is that V B is easy to understand, but you can also use V C + + or D e L P h i if you need to. This allows developers to use the language they are most familiar with.
? The components you create are not limited to returning and updating the recordset. A large number of encapsulated business logic can be built as part of data processing.
? You can encapsulate all conflict-handling code in the S e T R e c o RDS e T method, and return only the detailed description of the error. This indicates that the client script is canonical. At the same time, it also means that users cannot steal your well-written code.
The next section of this book describes the benefits of the component in more detail.
10.3.4 Register server-side components
As previously said, you must modify the registry before you create a server component in your Web browser. In order for RDS to be able to use components, you must add the component's P r o G I D to the following registry key:

Warning: Always be careful when editing the registry. It is always wise to back up the registry before you modify it.
After running r e g e d i t, select a D c L u n c h key, then select N E w from the e d i t menu and select K E y. Now enter P r o G I D for the component, as shown in Figure 1 0-1 3.

You should also consider making a few modifications to the registry to indicate that the component is "safe for scripting" so that it will fully meet the requirements of I e when it is running. At this point, you need to add two keys, and all two require the G U I D of the component.

The best way to do this is to create an Internet download package (Internet Download Package) using Visual Studio's Package and deployment Wi Z a r d. If the safe for initialization and safe for scripting options are selected, the registry will be updated when the package is installed on the server. If you do need to get the class I D of the component, the wizard can also create an HTML file with a <OBJECT> tag with the component Class I d.
10.3.5 Custom Processor
The RDS Data control is an excellent client tool that handles large amounts of data on the client side. Most examples have shown that a data control uses a fixed set of data, such as a U t h o r S table. However, examples of dynamic Data binding indicate that you can also let users decide which data they want to retrieve. This can be done by creating a button that provides the user with a text box to enter the table name, or even a SQL query string.
Of course, this increases the flexibility of the RDS data control, but at the expense of security. If users are not restricted in their use of the data, they will either feel confused or want to peek at the confidential financial data. So what we need is a flexible, but also limited, way of retrieving data.
To do this you can use a single processor that can be modified before the connection string or command is executed.
A processor is a text file that contains four parts, separated by a carriage return:
? Connect section: Determines the connection string.
? SQL section: Determining SQL statements and commands.
? UserList section: Determining the user.
? Logs section: Determine Logging capabilities.
The text file name defaults to M S D f m P. I n i, installed in the WI n d o w s default directory.
1. Connect section
The Connect section allows you to overwrite the connection string and access details, identified by one of the following two entries:
? [Connect default] indicates the default connection details.
? [Connect connect i o n n a m e] points out the details of the connection named connect i o n n a m E.
There are two pairs of names/values in this section, as shown in table 1 0-6.

For example:

This indicates that if the connection string for the data control is P u b s D a t a B s E, the user will log on to the database as G U e s t u S e r, and only read permissions. Therefore, if the user performs the following actions:


The value here overrides the Access permission value in the Connect section.
In order to correctly use the U S e r L s t section, the server must be able to authenticate the user, so this depends on the validation rules on the server. For example, if you use anonymous access, all users will connect to the server as the default user specified in the Web site's admin attribute of the I/S.
4. Logs Festival
The Logs section allows you to specify a write-error file name that is identified by [Logs]. Log records apply to all connections. If the log file does not exist, a new log file is created.

6. Using a custom processor
You can use the Handler property of the RDS data control to specify the processor and give the name of the specified processor. The default processor is M S D F. Handler, which is a component used in the RDS server-side section. You can also write your own custom processor (the standard C O m component), and if you do this, you should refer to the documentation for RDS.




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.