CONTROL PANELS
Hosting Accounts
Domain Accounts

REGISTER NEW
Hosting Account
Domain Account
Transfer Domain
WHOIS

DEDICATED SERVERS
REQUEST QUOTE
PLACE ORDER

SECURE CERTIFICATES
PLACE ORDER

SUPPORT
EMAIL
FAQs
FORUMS
NEWS

POLICIES & SECURITY
SERVICE AGREEMENT
ACCEPTABLE USE
PRIVACY & SECURITY

    
NETWORK DIVERSIONS






Database Open/DSNless connection  

Any ASP script that needs to connect to a database must open it on the server first. There are two ways:

  • a connection via a DSN
  • a DSNless connection

A DSN connection requires either the server administrator to setup a DSN on the server using the control panel, or that you use a 3rd party ASP component so your ASP scripts can make the registry changes on the server to create their DSNs as needed.

Microsoft has a knowledge base article at:
http://support.microsoft.com/support/kb/articles/q193/3/32.asp
which also deals with DSNless connections.

DSN connections generally at a minimum require a DSN name, user, and password. This line in our tutorial would open a DSN named "student" as a user named "student" with a password of "magic".

set conntemp=server.createobject("adodb.connection")
conntemp.open "DSN=Student; uid=student; pwd=magic"
set rstemp=conntemp.execute("select * from authors")

What if we didn't have a DSN? And we knew the name of the file (i.e. file based databases like Access, Paradox, FoxPro, etc.) or the name of the data source (SQLserver for example). Here is the way we could open a data source without a DSN! Note that you must know the actual filepath on the server, i.e. nwind.mdb is not good enough it needs to be "C:\thatserver\account17\nwind.mdb". Fortunately the server.mappath function can turn a filename into the proper fully qualified filename with path on the server.

set conntemp=server.createobject("adodb.connection")
cnpath="DBQ=" & server.mappath("yourtable.mdb")
conntemp.Open "DRIVER={Microsoft Access Driver (*.mdb)}; " & cnpath
set rstemp=conntemp.execute("select * from authors")

<HTML><HEAD>
<TITLE>nwind.asp</TITLE>
<body bgcolor="#FFFFFF"></HEAD>
<%
set conntemp=server.createobject("adodb.connection")

' DSNless connection to Access Database
DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtemp=dsntemp & "DBQ=" & server.mappath("nwind.mdb")
conntemp.Open DSNtemp
' DSNless connection to Access Database

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 all the records
do  while 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>

Here is a list of the typical ODBC driver names you must supply:

{Microsoft Access Driver (*.mdb)}
driver=SQL Server; server=216.200.66.129
                          ^ our SQL server address