<%@ Language=VBScript %> <% strPage="DSN's"%> Internet Solutions DSN FAQs

Using a System DSN

To connect using a System DSN, you'd do something like the following. Be sure to replace DSNName with your DSN name.

<%

Dim MyConn ' Connection Name
Dim RS ' Recordset Variable
Dim SQL ' Variable for SQL statement

Set MyConn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.Recordset")
MyConn.Open "DSN=DSNName;UID=UserID;PWD=Password;"

SQL="Select fieldname1, fieldname2 From tablename [Where conditions]"

' Execute the SQL statement and get Data in Recordset
Set RS = MyConn.Execute(SQL)

%>

If you have used the code above, when you want to display fields on your page, you'd simply do this:

<%=RS("email")%> <%=RS("email")%> <%=RS("fieldname")%>

That code would display whatever the field contents are.

Please be sure that you close your database connection at the end of the page:

<%  
RS.Close 
Set Rs = Nothing 

MyConn.Close 
Set MyConn = Nothing 

%>

If you need to learn more about using databases and DSNs, there are several good reference sites out there. Two good places to start are www.msdn.microsoft.com and www.4guysfromrolla.com.