ASP technology access Web database (reproduced)

xiaoxiao2021-03-06  55

I. Various solutions to the web database

There are currently a variety of technologies for accessing the web database in a Windows environment, mainly:

1. Community Gateway interface CGI (Common Gateway Interface)

CGI is an earlier implementation technology. Suitable for multiple server platforms such as UNIX, Windows, etc., but CGI development

High cost, difficulty in maintenance, limited function, does not have transaction processing, and take up more server resources.

2. Internet Database Connector IDC (Internet Database Connector)

IDC integrates in the ISAPI (Internet Server API), fully utilizing DLL technology, easy to expand, but programming

Compared with CGI, it is more complicated and applies only to small database systems.

3. Advanced Database Connector ADC (Advance Database Connector)

The ADC provides ActiveX Control to access the database, and its main feature is that the data query is browsing by the user.

Execute, there is a need to download some of the partial records in the server-side database to the user end, the system is over-selling, slow response

Only for special frequent database query operations.

4. Java / JDBC language programming

The Java language is an object-oriented, easy to transplant, multi-threaded language, can connect to the database via JDBC

. The software written in Java / JDBC is strong, suitable for a variety of operating systems, but it performs efficiency and execution speed.

Not ideally, there is currently unable to establish efficient and high speed applications.

5. Dynamic server page ASP (Active Server Page)

ASP is Microsoft's latest web application development technology, focusing on processing dynamic web pages and web databases.

Hair, flexible, simple, high performance, is the best choice for accessing the web database.

II. Introduction to ASP

1.ASP Access the principle of the database

ASP is a server-side script execution environment that can be used to generate and perform dynamic high-performance web server programs

.

When the user requests the ASP home page using the browser, the web server responds, call the ASP engine to execute the ASP file.

And explain the scripting language (JScript or VBScript), connect the database via the ODBC, by the database access group

Part ADO (ActiveX Data Objects) completes database operations, and finally ASP generates HT containing data query results.

The ML home page returns the user-end display.

Since the ASP is running on the server side, the results return to the user browser in the form of an HTML home page, so the ASP source

The order does not leak, adding the security confidentiality of the system. In addition, ASP is an object-oriented script environment, users can

Increase the ActiveX component to expand its function, expand application scope.

2. The structure of the 2.asp page:

The ASP program code is simple, universal, file name is ended, and the ASP file is usually composed of four parts:

1) Standard HTML tag: All HTML tags can be used.

2) ASP syntax command: ASP code in the <%> tag.

3) The server-side include statement: can use the #include statement to transfer other ASP code to enhance the programs

active.

4) Script language: ASP comes with JScript and VBScript two scripting languages, adding ASP programming capabilities,

Users can also install other scripting languages, such as Perl, REXX, etc.

3.ASP's operating environment

The current ASP can run in three environments.

1) Windows NT Server 4.0 Runs IIS 3.0 (Internet Information Server).

2) Windows NT WorkStation 4.0 Run Peer Web Server 3.0 or more. 3) Windows 95/98 runs the PWS (Personal Web Server).

Among them, the IIS function on NT Server provides the strongest support for ASP, which is created to create high speed, stable.

The best choice for the ASP homepage.

4.ASP built-in object

The ASP provides six internal construction objects for users directly:

1) Application object: responsible for managing all session information, available to all specified applications

Share information between households.

2) Session object: Store session information of a specific user, only by the user, when the user is in different web pages

When jump, the variable in the session is saved during the entire session of the user. SESSION object requires a cookie support

hold.

3) REQUEST object: The information passed from the user end to the server, is the main method of the ASP read user input

.

4) Response object: The server sends the output content to the user.

5) Server object: Provide access to the server about methods and properties.

6) Object Context object: Added objects for IIS 4.0 for transaction processing. This function needs

Support for MTS (Microsoft Transcation Server) management.

5. ASP's main built-in component:

1) AD Rotator Components: Used to automatically rotate the advertisement on the same page by specifying the same page, used for WWW last day

Beneficial advertising services.

2) Browser Capabilities Components: Determine the functional data of the user browser that accesses the web site, including

Type, performance, version, etc.

3) Database Access Components: Provide ADO (ActiveX Data Objects) to access the number of support ODBC

According to the library.

4) File Access Components: Provide read and write functions for server-side files.

5) Content Linking Components: Generate the list of contents of the web page, and connect each page to make navigation

Strip.

In addition, components such as MyInfo, Counters, Content Rotator, Page Count are also installed.

Actiive components can be prepared from your own to improve the practicality of the system.

6. Database Access Components ADO

The application on WWW is to access the web database. When using the ASP to access the web database, you must use the ADO components.

ADO is an ASP built-in ActiveX Server Component, through the web server

Set ODBC and OLEDB to connect multiple databases: such as Sybase, Oracle, Informix, SQL Server, ACC

ESS, VFP, etc., is the most effective and simple and straightforward approach to the database supported by Microsoft.

The ADO components provide the following seven objects and four collections to access the database.

1) Connection object: Establish a connection to the background database.

2) Command object: Execute SQL instructions to access the database.

3) Parameters object and Parameters collection: Provides data and parameters for Command objects.

4) RecordSet object: Store data information after accessing the database is the most frequently used object.

5) Field object and field collection: Provide the work of accessing the various fields of the current record in the Recordset

can.

6) Property objects and Properties collection: Provides information for Connection, Command, Recordset, Field objects.

7) Error object and Errors collection: Error information when accessing the database.

3. ASP Access Database Step

In ASP, use the ADO component to access the background database, you can use the following steps:

Define data source

Open the Control Panel on the web server, select "ODBC", select "Add" to "System DSN",

Select the type of database, name, location, etc. you want. This article defines "SQL Server" and the data source is "HT"

The database name is "HTDATA", and the scripting language uses JScript.

2. Use the ADO component to query web databases

1) Call the server.createObject method to obtain an instance of "AdoDb.Connection", then use Open

Method Open the database:

Conn = Server.createObject ("AdoDb.Connection")

Conn.open ("ht")

2) Specify the SQL command to be executed

After connecting the database, you can operate, such as query, modification, deletion, etc., these are all through SQL instructions.

Completed, if you want to query the code containing "X" in the data table signaltab

SQLSTR = "SELECT * from sign thealtab where code like '% x%'"

RS = conn.execute (SQLSTR)

3) Use the RecordSet attribute and method, and display the result

In order to more accurately track data, create a cursor containing data with the RecordSet component, the cursor is stored

Data in memory.

RS = Server.createObject ("AdoDb.Recordset")

RS.Open (SQLSTR, CONN, 1, A)

Note: A = 1 read

A = 3 new, modified, delete

In Recordset components, common attributes and methods are:

Rs.fields.count: The number of fields of the Recordset object.

RS (i) .name: The name of the i-th field, i is 0 to rs.fields.count-1

RS (i): Data of the i-th field, i is 0 to rs.fields.count-1

RS ("Field Name": Specifies the data of the field.

Rs.Record.count: The total number of data records in the cursor.

Rs.eof: Whether the last record is recorded.

Rs.MoveFirst: Point to the first record.

Rs.MoveLast: Points to the last record.

Rs.MovePrev: Refers to a record.

rs.MoveNext: Note the next record.

Rs.Getrows: Place the data in an array.

rs.properties.count: ADO's ResultSet or Connection attribute bit.

Rs.properties (item) .Name: The name of the ResultSet or Connection of ADO.

Rs.properties: The value of the ResultSet or Connection of ADO.

rs.close (): Turn off the connection.

4) Turn off the database

CONN.CLOSE ()

IV. Query the web database

The sample program below is the SignalTab table that accesses the SQL Server database, three fields in the table: CO

DE (Code field, character, 3), class (Classification field, character type, 10 bits), MEMO (note field, character type, 20). Data Source DSN: HT, User Name: Client, Password: Passwd.

Screen input page Input.asp

<% @ Language = javascript%>

Please enter the query condition please input condition </ title></p> <p></ hEAD></p> <p><form action = ShotQuery.asp method = "post" target = "_ self"></p> <p><Input Type = "text" size = 6 maxorength = 3 name = signalcode value = "code"> </ fo</p> <p>NT> </ p></p> <p></ center> </ div> <p> </ p></p> <p><Input Language = "JavaScript" type = "submit" value = "confirm" name = "b1"</p> <p><input type = "reset" value = "Clear" Name = "B2"></p> <p><Input Language = "javascript" type = "button" name = "b3" value = "Return"</p> <p>Onclick = "Window.history.back ()"></p> <p></ font> </ p></p> <p></ center> </ div></p> <p></ form></p> <p></ body></p> <p></ html></p> <p>Database handler SHOTQUERY.ASP</p> <p><! - # include virtual = "/ master / lib.inc" -></p> <p><script language = javascript runat = server></p> <p>Var signalcode = request.form ("signalcode");</p> <p>Dbconn = Server.createObject ("AdoDb.Connection");</p> <p>DBCONN.OPEN ("DSN = HT; UID = Client; PWD = Passwd");</p> <p>RS = Server.createObject ("AdoDb.Recordset");</p> <p>Var sqlstr = "Select * from signaltab order by code";</p> <p>RS.Open (SQLSTR, DBCONN, 1);</p> <p>IF (Rs.Recordcount <1) {</p> <p>Response.write ("<p> does not meet the requirements </ p>");</p> <p>Response.write ("<p> <form> <input type = 'button' value = 'Returns' OnCli</p> <p>CK = 'window.history.back ()' name = 'b1'> </ form> </ p> ");}</p> <p>Else {</p> <p>Response.write ("<p> <center> <b> data query results </ b> </ center> </ p>");</p> <p>Response.write ("<tr> <td> <b> code </ b> <td> <td> <b> classification </ b> </ td> <td> <b> 备 <</p> <p>/ b> </ td> ");</p> <p>For (var i = 1; i <= rs.pagesize; i ) {</p> <p>IF (! rs.eof) {</p> <p>Response.write ("<TD> <span style = 'font-size: 9t'> rs (" code ") </ span> </ td</p> <p>> ");</p> <p>Response.write ("<TD> <span style = 'font-size: 9t'>" rs ("class") </ span> </ t</p> <p>D> ");</p> <p>Response.write ("<TD> <span style = 'font-size: 9t'>" RS ("MEMO") </ SPAN> </ TD</p> <p>> ");</p> <p>Response.write ("</ TR>");</p> <p>rs.movenext ();</p> <p>}</p> <p>Else Break;</p> <p>}</p> <p>Response.write ("</ Table> </ form>");</p> <p>Rs.close ();</p> <p>Dbconn.close ();</p> <p>}</p> <p></ script></p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-112866.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="112866" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.046</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'Tayv_2FVHCfqoe101J5b9Rpnfzxh6K5j7Hf1CO_2B4SsI9_2BH84JJAscWp5LJboL8dLBzMDpmmOSOMaS8WukhfGETzg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>