Using Databases in ASP

Source: Internet
Author: User
Tags dsn access database
One of the most important features of ASP is that it makes it easy for you to connect to a database. is usually connected to an access or an SQL database. Because access is the easiest to start with, and you may already have access on your machine, in the example below, we'll use access for example. Once you've learned the core technology for ASP and Access database connectivity, when you start using SQL Server, you'll find that the key technologies needed are essentially the same.
Transfer from: China Software network www.csdn.com.cn
When you want to connect to the database, you need to open the database on the server. You can connect and open a database by using a data source name (DSN) or by using a dsn-less connection directly in your scripting language.
Create a data source name (DSN)
You can make your database available for use in ASP by creating a System DSN in the Control Panel for your database. You can create several DSNs on your local computer, each of which corresponds to a different database that you use. After you have created the DSN, you can test your page on your local server. If your site is made up of
ISP provides services, and the ISP supports ASP, it is very likely that it will provide a GUI interface to create a DSN for your database.
In Windows 95/98/NT, open the Control Panel (Start menu-> set-> Control Panel) and double-click ODBC to enter.
Select System DSN and click Add.
Select Microsoft Access Driver and click End.
Fill in the data source name. This is the name you gave to your database, so it's the same operation as an alias.
Click the Select button in the database selection to browse the location of the Access database you created in the system.
Click OK
The new DSN now appears in the System DSN and can be used on your local server.
Connecting to a database
Let's build a dsn-less connection and see how it connects to the database. When you create a DSN, you have stored some information about the database, so you don't need to repeat them every time you need to use some information, such as database type, name, location, and optional, user and password.
To create a dsn-less connection, you need to provide the same information. The following example shows how to create a dsn-less connection to a database called products:
<%
strconnect = "Driver={microsoft Access Driver (*.mdb)}; Dbq=c:dbproducts.mdb "
Set objconn = Server.CreateObject ("ADODB. Connection ")
Objconn.openstrconnect
%>
The second line defines the drive and physical path of the database. In order to use a dsn-less connection, you need to know the actual location of the file (absolute path). Server.MapPath provides a simple working environment for anyone using the host service to find the actual access paths that are difficult to find.
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.