ASP PART 1 ere, you point out how DSN-less connections are faster than System DSN connections because DSN-less avoids doing a registry lookup. This is true; furthremore you can receive additional performance benefits by directly using the OLEDB layer
Here is an example:
Dim Conn, dbPath
dbPath = "d:\myaccessfile.mdb"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & dbPath
I have noticed rather large performance gains, both in server resources and browsing speed on the client with just this change in the code. Create DSN-Less Connection and use MapPath Method
<%
Option Explicit
' Dimension Local variables
Dim objConn ' Connection Name
Dim strConn ' Connection String
Dim objRS ' Recordset Variable
Dim strSQL ' variable for SQL statement
Dim intTotalColumns
Dim intCounter
Const adOpenStatic = 3
Const adLockReadOnly = 1
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
strConn = "DBQ=" & Server.MapPath("MyDatabase.mdb")
strConn = "DRIVER={Microsoft Access Driver(*.mdb)};" & strConn
objConn.Open strConn
strSQL = "SELECT * FROM Links"
objRS.open strSql, objConn, adOpenStatic, adLockReadOnly
' get the total number of columns
intTotalColumns = objRS.Fields.Count - 1
%>
<TABLE BORDER="1" WIDTH="500">
<tr>
<%
' first display the column names
For intCounter = 0 To intTotalColumns
%>
<TD>
<B>
%=objRS(intCounter).Name%></B>
</TD>
<%
Next
Response.write "</TR>"
' now loop through the recordset and display the data
Do Until objRS.EOF = True
Response.Write "<TR>"
For intCounter = 0 To intTotalColumns
Response.Write "<td width=100 align=center>"
Response.write objRS(intCounter).value
Response.Write "</TD>"
Next
Response.Write "</TR>"
objRS.Movenext
Loop
%>
</TABLE>
<%
' Close Recordset
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%> Want more of ASP OR ASP.NET????ask me... |