Alternative: ASP access to the database without DSN

Source: Internet
Author: User
Tags dsn requires
Access | data | Database A DSN connection requires the server's system administrator to set up a DSN with the ODBC tool in Control Panel on the server, or use a Third-party server component to have your ASP script create DSN by modifying the registry when needed.

A DSN connection usually requires parameters such as: DSN name, username, password, for example, we use the username "student", Password "magic", through the DSN "student" to establish a connection:

1. Set Conntemp=server.createobject ("Adodb.connection")
2. Conntemp.open "dsn=student; Uid=student; Pwd=magic "
3. Set Rstemp=conntemp.execute ("SELECT * FROM authors")

What do we do if we don't have a DSN?

But we know the file name (for example, a Access,paradox,foxpro database) or a data source name (for example, SQL Server database). Here's a way we can access the database without DSN. Note that you must know the actual file path! For example: "C : \thatserver\account17\nwind.mdb ".

Fortunately, the method Server.MapPath can return the address on the server.

1. Set Conntemp=server.createobject ("Adodb.connection")

2. Cnpath= "dbq=" & Server.MapPath ("Yourtable.mdb")

3. Conntemp. Open "Driver={microsoft Access DRIVER (*.mdb)};" & Cnpath

4. Set Rstemp=conntemp.execute ("SELECT * FROM authors")

<HTML><HEAD>

<TITLE>nwind.asp</TITLE>

<body bgcolor= "#FFFFFF" ></HEAD>
<%

Set Conntemp=server.createobject ("Adodb.connection")
' Do not use DSN to establish a connection

dsntemp= "Driver={microsoft Access DRIVER (*.mdb)}; "

Dsntemp=dsntemp & "dbq=" & Server.MapPath ("Nwind.mdb")

Conntemp. Open dsntemp

' Do not use DSN to establish a connection
Set Rstemp=conntemp.execute ("SELECT * from Customers where country= ' Germany '")

Howmanyfields=rstemp.fields.count-1

%>
<table border=1>

<tr>
<% ' put headings on the Table of Field Names

For i=0 to Howmanyfields%>
<td><b><%=rstemp (i). Name%></b></td>
<% Next%>
</tr>
<% ' Now lets grab the records

Do as not rstemp.eof%>
<tr>
<% for i = 0 to howmanyfields%>
&LT;TD valign=top><%=rstemp (i)%></td>
<% Next%>
</tr>
<% Rstemp.movenext

Loop

Rstemp.close

Set rstemp=nothing

Conntemp.close

Set Conntemp=nothing%>
</table>

</BODY>

</HTML>

The following is a typical driver parameter value:
{Microsoft Access Driver (*.mdb)}
Driver=sql Server; server=127.0.0.1
^ SQL Server's IP address

Do not access SQL and access through a data source
Using SQL Server 6.5:
Set Conn = Server.CreateObject ("ADODB. Connection ")
Conn.Open "Driver=sql Server; Server=server_name; Uid=your_uid; PWD=YOUR_PW; Database=your_database; "

Using Access:
Set Conn = Server.CreateObject ("ADODB. Connection ")
Conn.Open "Driver={microsoft Access DRIVER (*.mdb)}; Dbq=c:\www\db\guestbook.mdb "



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.