MyEspinda! .Customers Login Here

List records from a database without an ODBC connection (DSNLESS)

You do not need to add use an ODBC connection if you specify a connection which references the database direct rather than via an ODBC Data Source Name. Espinda recommends that you do this by using Microsoft's ADO (ActiveX Data Objects) interface to access OLE DB drivers. This method is know as a DSNLESS connection.
Example
The following example uses a direct ADO connection to read customers from an MS Access table via ASP (Active Server Pages):

<%
'initialise objects and variables
dim conn, strsql, rsuser, strMDBPath
set conn=server.createobject("ADODB.Connection")
set rsuser=server.createobject("ADODB.Recordset")
strMDBpath = Server.MapPath("..\private\northwind.mdb")
direct connection
conn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & strMDBPath
strsql = "select top 10 (city) from customers"
rsuser.open strsql,conn,1,2
'iterate thro recordset
Do while not rsuser.eof
response.write rsuser("city") & "<br>"
rsuser.movenext
Loop
'close resources used
rsuser.close
conn.close
clean up
set rsuser=nothing
set conn=nothing
%>

NOTE: Take care to clean up objects after they have been used. In the above example, the connection and recordset objects are closed and then destroyed.

Home|About Espinda|Hosting Plans|Tools|FAQ|Contact|Support|Terms of Service|Site Map|Order