This article discusses several practical methods for connecting pages to databases in ASP, and finally provides a function access
The SQL Server database example has important practical significance for the development of network automation systems. Keywords: ASP database connection
Internet function modules such as message boards, discussion groups, online voting, online surveys, and chat rooms are everywhere on the Internet.
A variety of office automation network systems are also running in a Multi-unit Small Lan, these programs are using ASP (Active Server)
Page. Establishing a connection between the page and the database source is a step to access the database and the most important step.
.
In the ASP script, you can connect to the database through three practical methods: establish a connection through odbc dsn, establish a connection through oledb and
Driver to establish a connection.
1. Establish a connection through ODBC DSN
To use the ODBC data source, you must first set the data source in ODBC on the control panel, and then write a script to establish a connection with the database source.
1. Create an ODBC DSN
You can open the control panel in the Start Menu of Windows to create a DSN-based file. Double-click the ODBC icon.
Then, select the "system DSN" property page, click "add", select the database driver, and then click "Next ". Follow the instructions below to configure
The DSN for your database software. Common Database software include Microsoft Access and SQL Server.
Server database as an example.
Configure the database system DSN of SQL Server: if the database resides on a remote Server, contact the Server administrator.
To obtain additional configuration information. The following process uses the default ODBC settings of SQL Server, which may not apply to your hardware configuration.
. In the "Create new data source" dialog box, select "SQL Server" from the list box and click "Next ". Type
And then click "Next ". Click "finish" to create a data source. Enter the name and logon ID of the server that runs the SQL service program.
And password. In the "create SQL Server new data source" dialog box, type A database containing SQL Server in the "Server" list box.
And then click "Next ". Select the login ID verification method. If you want to select SQL Server verification, enter
A logon ID and password, and then click "Next ". In the "create SQL Server new data source" dialog box, set the default database
, The driver and ansi id set for the stored procedure, and then click "Next ". (For details, click "help ".) In
In the dialog box (also named "create SQL Server's new data source"), select a character conversion method and click "Next ". (
For more information, click "help ".) In the next dialog box (also named "create SQL Server's new data source"), Select log on
. Note that in typical cases, you can only use logs to debug database access problems. On the "ODBC Microsoft SQL Server Security
In the package dialog box, click test data source ". If the DSN is created correctly, the "test result" dialog box indicates that the test is successful.
2. write scripts and establish a connection with the database source.
ADO (ActiveX Data Objects) provides a Connection object that can be used to create and manage applications and
The connection between ODBC databases. Connection objects have various attributes and Methods. You can use them to open and close database connections.
To write a database Connection script, first create an instance of the Connection object and then open the database Connection:
2. Establish a connection through oledb
Use the oledb method to establish a connection between the page and the database. You do not need to create an odbc dsn data source. Write the following script and data source directly.
Establishing a connection is a simple and easy-to-use method.
3. Establish a connection through driver
You do not need to create an odbc dsn data source to establish a connection between the page and the database through the driver, but you must know the actual database file path.
Path or data source name (for example, SQLserver database ).
4. instance (LOGIN System)
Whether you enter the forum to express your opinion or enter the automated management system, you must enter the login information.
Check whether the user registration information exists in the Database. If the user registration information is detected, the user can log on smoothly. The implementation of this logon check process,
You need to connect the back-end database to the front-end page.
Code implementation: the connection script can be written into a single page named conn. asp, which can be referenced as needed. You can also directly write it on the logon check page.
.
Conn. asp source code:
Login_check.asp (logon check page)
An error occurred while processing the SSI File
V. Conclusion
This article introduces several practical methods for connecting to the database, which can be used to easily connect pages to the SQL database. Page and number
The database connection is the foundation of the automation system. In fact, the validity of the database is very important. The method described in this article is a summary of the author's extensive practical experience,
In fact, the validity has been verified.