Describe in your own language the process of connecting a database to a program.

Source: Internet
Author: User
Tags dsn ole

I. Establishing a connection through an ODBC DSN using an ODBC data source, you must first set up the data source in ODBC in Control Panel, and then write the script and the database source to establish the connection.

       1, create an ODBC DSN     you can create a DSN-based file by opening Control Panel on the Windows Start menu. Double-click the ODBC icon, select the System DSN property page, click Add, select the database driver, and then click Next. Follow the instructions below to configure the DSN that applies to your database software. Common database software is Microsoft Access, SQL Server, and so on, with SQL Server databases as an example.     Configure SQL Server database system   DSN: Note If the database resides on a remote server, contact your server administrator for additional configuration information, and the following procedure uses the ODBC default settings for SQL Server It may not apply to your hardware configuration. In the Create New Data Source dialog box, select SQL Server from the list box, and then click Next. Type a name for the DSN file, and then click Next. Click Finish to create the data source. Type the name, login ID, and password of the server running the SQL service program. In the Create new data source for SQL Server dialog box, in the Server list box, type the name of the server that contains the SQL Server database, and then click Next. Choose how you would verify your login ID. If you want to select SQL Server Authentication, enter a login ID and password, and then click Next. In the Create new data source for SQL Server dialog box, set the default database, the driver for stored procedure settings, and the ANSI identity, and then click Next. (To get more information, click Help.) In the dialog box (also named "Create new data source for SQL Server"), select a character conversion method, and then click Next. (For more information, click Help.) In the next dialog box (also named "Create new data source for SQL Server"), select login Settings. Note Typically, you can only use logs to debug database access issues. In the ODBC Microsoft SQL Server Setup dialog box, click Test Data source. If the DSN is created correctly, the test Results dialog box indicates that the test completed successfully.

       2, scripting, and database source establish connections       ADO (ActiveX Data Objects) provides A Connection object that you can use to establish and manage connections between an application and an ODBC database. Connection objects have various properties and methods that you can use to turn database connections on and off. To write a database connection script, you first create an instance of the Connection object, and then open the database connection: <% set Conn=server.createobject ("Adodb.connection") Conn.Open "dsn= ODBC name; database= database name; uid=; pwd=; "%> to establish a connection through OLE DB the OLE DB method is used to establish a connection between the page and the database, without creating an ODBC DSN data source, and directly writing the following script and data source to establish a connection, is an easy-to-use method. <% set Conn=server.createobject ("Adodb.connection") conn.open "provider=sqloledb;server= (SQL Server name or IP address); database= database name; uid=;p wd= "%>

       Build a connection through driver the connection between the page and the database is established through driver, and you do not need to create an ODBC DSN data source. However, you must know the actual database file path or the data source name (for example, SQL Server database). <% set Conn=server.createobject ("Adodb.connection") Conn.Open "Driver={sql server};server= (SQL Server name or IP address); database= database name; uid=;p wd= "%> Four, instance (landing system)    whether it is to enter the forum to express their views, or into the automation management system, users need to fill in the login information, The system checks the user's registration information in its own database, and if detected, the user can log in successfully. The implementation of this login check process requires that the background database be connected to the foreground page. Code implementation: The connection script can be written separately as a page named conn.asp, you need to refer to. It can also be written directly on the login check page.

Conn.asp Source code: <% Set Conn=server.createobject ("Adodb.connection") Conn.Open "DSN=TEST;DATABASE=TEST;UID=CZX; pwd=czx123; "%> login_check.asp (Login Check page) <!--#include file=" conn.asp "-<% Dim name,pwd Name=trim (Request ( "Name")) Pwd=trim (Request ("pwd")) If Request ("B1") = "Login" then  set rs=server.createobject ("Adodb.recordset")  sql= "SELECT * from member where loginname= '" &name& "'"  rs.open sql,conn,1,1  if  rs.eof and Rs.bof then     Response.Write "You are not authorized to enter, please register a new user first. " else   If RS (" password ") =pwd then   session (" Memid ") =rs (" id ")   rs.close   set rs=nothing &nbs P Response.Redirect "index.asp"  end if End If End if Conn.close set conn=nothing%>

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.