WinHost Support Portal
Language
 
Home>Knowledge Base>Programming/Error Message/Sample Code>Sample code>How to query a SQL Server with DSN/ODBC name source
Information
Article ID759
Created On1/28/2010
Modified4/13/2010
Share With Others
How to query a SQL Server with DSN/ODBC name source
<
Dim cnnSimple  ' ADO connection 
Dim rstSimple  ' ADO recordset 
Set cnnSimple = Server.CreateObject("ADODB.Connection") 
 
' DSNLess 
cnnSimple.Open ("DSN=[DSN Source Name]; User Id=[DB Login];Password=[DB password];") 
 
Set rstSimple = cnnSimple.Execute("select * from sysfiles") 
%> 
<P> Connecting to Access with Ole connection </P> 
 
<table border="1"
<
Do While Not rstSimple.EOF 
 %> 
 <tr> 
  <td><%= rstSimple.Fields(0).Value %></td
  <td><%= rstSimple.Fields(1).Value %></td
 </tr> 
 <
 rstSimple.MoveNext 
Loop 
%> 
</table> 
<
 
rstSimple.Close 
Set rstSimple = Nothing 
cnnSimple.Close 
Set cnnSimple = Nothing 
%> 

If you run in to problems using this code, please post in our community forum. Technical support cannot assist with specific coding related issues.