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%>
<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 "