A: ASP connection MS-SQLServer2000 Database
----------------------------------------------------------
<%
Sessiontimeout = 50000 'set the session expiration time
If trim (request. Cookies ("myname") <> "" then
Session ("uid") = trim (request. Cookies ("myname "))
End if
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open "driver = {SQL Server}; server = xiegang; uid = sa; Pwd = SQL; database = guestbook ;"
Set rs = server. Createobject ("ADODB. recordset ")
%>
Ii. asp connection to access database
-----------------------------------------------------------
<%
Dim Conn
Dim connstr
Dim DB
DB = "database/yiuwekdsodksldfslwifds. mdb" 'location of the database file
Set conn = server. Createobject ("ADODB. Connection ")
Connstr = "provider = Microsoft. Jet. oledb.4.0; Data Source =" & server. mappath (db)
Conn. Open connstr
Sub closeconn ()
Conn. Close
Set conn = nothing
End sub
%>
Test Platform:
MySQL 4.0 for radhat Linux (for Windows can also be used)
Windows 2003 Standard Edition Windows XP English
1. Install myodbc
========================================================== ========================
1. Visit www.mysql.com and download myodbc. We use version 3.51.
Http://dev.mysql.com/downloads/connector/odbc/3.51.html
2.install mydbcto run the downloaded mydbc-3.51.06.exe file in windows.
(File names vary by version)
2. Establish an ODBC connection
========================================================== ========================
Go to Control Panel> ODBC Data Source
At this time, we can see that there is already one in the user DSN: myodbc3-test, note that the driver {MySQL ODBC 3.51 driver} parameter on the right must be a conection string for connecting ASP to the database ).
Add a "system DSN"
Select "system DSN" in the dialog box, and click "add" on the right. This will allow you to select a data source. Select MySql ODBC 3.51 driver. Press "end ".
At this time, a configuration dialog box will pop up:
Data Source Name: name of the DSN used in the program.
Host/server name (or IP) host/server name (or IP address). If it is a local machine, enter localhost
Database Name: name of the database to be used in the program.
User: the user name used to log on to MySQL. Pay special attention to the following,
Root users can only log on to the local machine due to security issues. Of course,
You can remove this function by modifying the user table.
Password Key: the logon password.
Port: use the default value. Do not change it unless you are sure.
After all settings are complete, press "Test Data Source" and the screen will show that the connection is successful.
All configuration is done!
Iii. asp and database connection========================================================== ======================
The following is the source code for connecting to MySQL. The connected database name is teacher,
The table name is school. The table has two fields: Name and ID.
<HTML>
<Head>
<Title> MySQL connection test </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
</Head>
<Body>
<% Strconnection = "DSN = mysqltest; driver = {MySQL ODBC 3.51 driver}; server = 127.0.0.1; uid = root; Pwd = xgsa; database = School"
'Connection string. DSN is the data source identifier we set. Note that we mentioned the driver when setting the system DSN.
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open strconnection
SQL = "select * from Teacher" 'SQL query statement
Set rs = conn.exe cute (SQL)
If not Rs. bof then %>
& Lt; table width = "167" & gt;
<Tr>
<TD width = "76"> <B> name </B> </TD>
<TD width = "79"> <B> sex </B> </TD>
</Tr>
<% Do while not Rs. EOF %>
<Tr>
<TD> <% = RS ("name") %> </TD> Name field
<TD> <% = RS ("ID") %> </TD> sex field
</Tr>
<% Rs. movenext
Loop %>
</Table>
<% Else
Response. Write ("sorry, no data found .")
End if
Rs. Close
Conn. Close
Set conn = nothing
Set rs = nothing %>
</Body>
</Html>