by Matt Massey (4 Submissions)
Category: Active Server Pages
Compatability: ASP (Active Server Pages)
Difficulty: Unknown Difficulty
Originally Published: Sun 31st January 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)
DSN-less database connection with simple database example.
Generic.DSN
------------------------------------
[ODBC]
DRIVER=Microsoft Access Driver (*.mdb)
UID=admin
UserCommitSync=Yes
Threads=3
SafeTransactions=0
PageTimeout=5
MaxScanRows=8
MaxBufferSize=512
ImplicitCommitSync=Yes
FIL=MS Access
DriverId=25
GenericDSN.asp
------------------------------------
<%
sDB = "YourDatabase.mdb" ' Be sure to substitute your database name here
sScriptDir = "/virtual/dir/" ' This is the VIRTUAL directory the database is in
sPath = Server.MapPath(sScriptDir) + "\"
TheDSN = "filedsn=" & sPath & "Generic.Dsn;DefaultDir=" & sPath & ";DBQ=" & sPath & sDB & ";"
%>
Sample.asp
------------------------------------
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open AdDSN,"",""
SQL = "SELECT * FROM Your_Table;"
Set RS = CreateObject("ADODB.Recordset")
RS.Open SQL, Conn, 3, 3
%>
Access your database fields here by using:
Fieldname: <% =RS("FieldName") %>
or loop through all records in the recordset.
<%
If RS.RecordCount > 0 then
RS.MoveFirst
Do While Not RS.eof
Response.Write "Field Name:" & RS("FieldName") & "<BR>"
RS.MoveNext
Loop
Else
Response.Write "No Records Found"
End If
%>
<%
RS.Close
Set RS = nothing
Conn.Close
Set Conn = nothing
%>