Database Solution for Personal homepage asp bis

Source: Internet
Author: User
Tags dsn odbc odbc connection access database
You can see that the ASP's syntax is VBScript, and its object-oriented thinking is similar to VB, so, as long as you first pass VB or VBScript, that ASP can easily on the ground hand.

The above part can be said to be the essence of ADO in ASP, we discuss the content of the code <% and%> is the beginning and end of ASP code. When the server returns a user request, it interprets the contents of <% and%> as standard HTML code and sends it to the client browser. When you access a database, you first establish a connection, that is, declare an instance of a connection class (object), and then use the Open method of the connection class to connect the connection object to an ODBC data source, in the example DSNname, which is a DSN. As for what is DSN, the following will be introduced, and first press not the table. To this end, the database connection has been completed, the following is the operation of the database.

The operation is also simple, defining an SQL statement string, and then invoking the execution of the connection Execute method, which is stored in the object of a recordset class (which can be viewed as a table that temporarily holds data), in the example of Recustomerlist. In this way, the database query call is completed, and then simply output it.

In doing while ... When the loop is output, the write method of the Respond object in the ASP is invoked, which can generally be abbreviated to "=". The Statement recustomerlist (field name) returns the value of the corresponding field in the current record. The last call is the MoveNext method of the recordset class, which moves the record pointer to the next record, and executes repeatedly until the recustomerlist EOF (end of file) is true. In this way, the returned query results are exported.

This is just a little bit of basic knowledge of ASP data access, but we can get a glimpse of the powerful capabilities of ASP.

2. Now we can access the database through ASP to achieve dynamic effect. But there is another problem: most of the personal free Web pages available for ASP support are not supported by the database. In other words, you cannot build and own your own database in its database system. If you use the local database, you can not configure the server host ODBC, can not get your local database DSN, you can not access the database through ASP. How to solve this problem? The following discussion will give you an easy way to do this, which is the file DSN.

First, explain a few nouns

DSN: According to the official Microsoft documentation, DSN means "the application is used to request the name of a connection to an ODBC data source (CONNECTION)", in other words, it is a symbol that represents an ODBC connection. It hides details such as database file names, directories, database drivers, user IDs, passwords, and so on. So when you build a connection, you don't have to think about the database file name, where it is, and so on, just give it a DSN in ODBC.

FILE DSN: When we discuss this issue, let's look at other types of DSN

System DSN: This DSN can be used by any user who logs on to the system.

User dsn: This is a DSN that is established for a specific user. Only the user who created the DSN can see and use it. In both cases, the details of the DSN are stored in the system's registry.

Once you know the preliminary knowledge above, let's see what a file DSN is. The file DSN stores the details of the DSN in a file, rather than in the system registry. This file is a simple text file with the. dsn as the extension.

While this sounds simple, you need to know the parameters that make up the DSN file. A simple DSN file for accessing access is given below.

-----FILE.DSN

[ODBC]

Driver=microsoft ACCESS DRIVER (*.mdb)

Readonly=0

Usercommitsync=yes

Threads=3

Safetransactions=0

Pagetimeout=5

Maxscanrows=8

maxbuffersize=512

Implicitcommitsync=yes

Fil=ms ACCESS

Driverid=25

Name it file.dsn, of course, you can change your name according to your wishes.

After the establishment of this document, the work has been completed in half. The next task is to establish a connection. When using a System DSN, establishing a connection simply refers to the system DSN:

Conn.Open "MyDSN" (Conn is the name of the connection object)

When applying the Fils DSN as above, you need to add more parameters to explain.

Conn.Open "FILEDSN=C:\WEBDIR\FILE.DSN;DBQ=C:\DATABASE\MYDB.MDB; Uid=admin; Pwd=admin; "

C:\webdir is the directory where the. dsn file resides, and it needs to use the physical path of the file. You can use the Server.MapPath method to get it. such as Server.MapPath ("/mysite/file.dsn"). Also, this is necessary for DBQ parameters. The UID and PWD parameters are optional.

Jane, to create a reusable file DSN

1 The DSN parameter is used to establish a text file with the name of DSN extension.

2 use FILEDSN and DBQ parameters to establish the connection, you can use Server.mpapath to get the physical path.

3 You can use this file DSN on any Access database simply by changing the DBQ, UID, and PWD parameters.

It is worth noting that different parameter values and some additional parameters are applied to databases of other non-access types.



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.