ASP connection SQL Server database several methods

Source: Internet
Author: User
Tags dsn access database

Linking SQL Server databases in ASP

Methods in database Link 2 in ASP

1, directly with the string link, the code is as follows:

The code is as follows Copy Code
<%
' Connect to the database
Dim Conn
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn. Open "Driver={sql server};server= host IP address; uid= user name; pwd= password; database= database name "
%>

2. Use DSN (data source) Link, this method you want to create a DSN first, create a method click the Server/Control Panel/admin tools/Data Source (ODBC) icon, Open Data Source Manager, and create a SQL Server data source in the System DSN tab. The link code is as follows:

The code is as follows Copy Code

<%
' Connect to the database
Dim Conn
Set conn=server.createobject ("Adodb.connection")
Conn. Open "dsn=article;uid= user name; pwd= password;"
%>

However, the two methods used in DW MX are as follows:

1. Define a site in the files panel
2. Click the Plus button in the Database tab of the application panel to select Custom Connecting string (custom link string, which is a method link) or Data Source Name (DSN, Two ways to link, open the floating panel, fill in the parameters can be.

I think no matter how to write a program with DW MX, for database connection files (commonly used is conn.asp), I have two suggestions, one is the best use of handwritten connection file online (below in detail how to write), the second is to refer to the database at the beginning of the file to use <!– #include File= "Connections/conn.asp" –>, called the database, so that the name or location of the database change is easier.

Second, explain how to write a conn.asp file. The simplest is

The code is as follows Copy Code

<%
Dim conn
Dim connstr
Connstr= "dbq=" +server.mappath ("Data/database.mdb") + ";D efaultdir=;D river={microsoft Access DRIVER (*.mdb)};"
Set Conn=server.createobject ("ADODB. CONNECTION ")
Conn.Open ConnStr
%>

About Server.MapPath ("Data/database.mdb") explain. This example uses a relative path, meaning that the conn.asp is in the same directory as the data directory. If the conn.asp directory is in the same directory as the data directory, then Server.MapPath (". /data/database.mdb ").

You can also use the absolute path Server.MapPath ("/data/database.mdb"), meaning that the data is the root directory, and conn.asp there is no relationship

Finally, on the issue of using SQL databases, different home service providers are different. The following is a new network of CHINADNS solutions for everyone to refer to.

1. Install a client software for SQL Server
2. Click to start-〉microsoftsqlserver2000-〉enterprisemanager on the local taskbar
3. After opening the SQL Server client software, click the Newsqlserver in the action in the file bar
Registration, then fill in the IP address of your SQL Server, username and password (same as FTP username password) After the Click Completes, will appear 211.154.211.xx?? Registeredsuccessfully, this indicates that your database has been opened.
4. Select your database in the Consoleroot IP, click the right mouse to choose Connect, the normal speed should appear under a successful connection icon.
5. After successful connection, select 211.154.211.xx-〉database-〉www_domainname_com to open your database
6. When you open tables, you will see a list of all types of system, you can newtable the table in the right mouse, or view the contents of the table with OpenTable. You can also use the import or output in step 2 to pour, the table operation related Operations Please check the relevant pages and books.

Report:

1.ASP Connect Access database statements

The code is as follows Copy Code

Setconn=server.createobject ("ADODB.") Connection ")
Connstr= "dbq=" +server.mappath ("Aaa/bbspp1.mdb") + ";D efaultdir=;D river={microsoft accessdriver (*.mdb)};D riverid= 25;fil=msaccess; Implicitcommitsync=yes; maxbuffersize=512; maxscanrows=8; pagetimeout=5; safetransactions=0; threads=3; Usercommitsync=yes; "
Conn.openconnstr

of which Setconn=server.createobject ("ADODB." Connection ") is the path that tells the server Access database to create an object Server.MapPath (Aaa/bbspp1.mdb) to access the data

2.ASP Connect SQL Server database statements

The code is as follows Copy Code
Setconn=server.createobject ("ADODB.") Connection ")
Conn. Open "driver={sqlserver};server=202.108.32.94; Uid=userid;pwd=password;database=www_panwei_com "
Connopen

                 
of which/setconn=server.createobject ("ADODB." Connection ") is the connection object for setting up a database
Driver= () tells the attached device name to be Sql-server
Server is the IP address of the connected servers, UID refers to the user's user name, PWD refers to the user's password,
Database is the name of the user database on the server side//

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.