ASP advanced article online management update-database connection

Source: Internet
Author: User
ASP advanced article online management update-database connection
Source: 2005-12-27 11:42:57
 
ASP advanced article online management update-database connection

 

<P style = line-height: 150%> author: Beach kiddies

 

<P style = line-height: 150%> in the previous section, we introduced the database structure of the article management system. After creating a database, we need to use ASP to establish database-related programs, including connecting to the database, displaying the database content, updating the database and other related programs, so this article will show you how to connect to the database in the management system and open the database. In ASP programs, programs that establish database connections are generally put into a single file separately, and will be directly used later <! -- Include file = "xxx. asp "-->, it is more convenient to change the database name in the future. If you write the database connection Statement on every page, and if you modify the database name in the future, you do not need to modify every file. Now you have used a separate file to directly INCLUDE it, only one file can be modified to achieve the same effect, which is also a small skill in ASP programming :)

 

<P style = line-height: 150%> The following describes how to establish a database connection:

 

<P style = line-height: 150%> Create an ASP file conn. asp. You can call the database later. <! -- Include file = "conn. asp" -->. The content and description of conn. asp are as follows:

 

<P style = line-height: 150%> <%
Dim conn
Dim connstr

 

<P style = line-height: 150%> "execution subroutine
Call conn_init ()

 

<P style = line-height: 150%> "subprograms connected to the database
Sub conn_init ()

 

<P style = line-height: 150%> "to respond to program interruptions caused by incorrect running time, it can move the control to the statement next to the wrong statement generated, you can continue to process the application without using this statement. Once an error occurs, the program stops and an error message is displayed to the user!
On error resume next

 

<P style = line-height: 150%> "use server. MapPath to specify the database path. The path here is the relative path.
Connstr = "DBQ =" + server. mappath ("bookid. mdb") + "; DefaultDir =; DRIVER = {Microsoft Access Driver (*. mdb )};"

 

<P style = line-height: 150%> "connect to the database using the Connection object
Set conn = server. createobject ("ADODB. CONNECTION ")

 

<P style = line-height: 150%> "open the connected database
Conn. open connstr
End sub
%>
In this way, a complete database connection and file opening are completed, and the database and its connection are completed. Next, we should introduce how to add data to the database, of course, it cannot be added directly to the database, so it will lose the meaning of this program :) the next section will introduce you to online addition and storage of articles.

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.