Query a SQL database with ASP using a DSN-less connection

DETAILS

<%
Dim cnnSimple  ' ADO connection
Dim rstSimple  ' ADO recordset
Set cnnSimple = Server.CreateObject("ADODB.Connection")
' DSNLess
cnnSimple.Open "Provider=SQLOLEDB;Data Source=YOURDBSERVER;" _
            & "Initial Catalog=YOURDBNAME;User Id=YOURUSERID;Password=YOURPASSWORD;" _
            & "Connect Timeout=15;Network Library=dbmssocn;"
Set rstSimple = cnnSimple.Execute("SELECT * FROM tbltest")
%>
<P> Connecting to SQL DB with DSNless connection </P>
<table border="1">
<%
Do While Not rstSimple.EOF
            %>
            <tr>
                        <td><%= rstSimple.Fields("id").Value %></td>
                        <td>%>= rstSimple.Fields("name").Value %></td>
            </tr>
            <%
            rstSimple.MoveNext
Loop
%>
</table>
<%
rstSimple.Close
Set rstSimple = Nothing
cnnSimple.Close
Set cnnSimple = Nothing
%>
     

  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

Send mail using CDO

DETAILS<% set objMessage = createobject("cdo.message")set objConfig =...

Query MySQL database in ASP

DETAILS<%Dim cnnSimple  ' ADO connectionDim rstSimple  ' ADO recordsetSet cnnSimple...

Query MySQL Database in ASP.net

DETAILS<%@ Page Language="VB" %><%@ import...

Insert data into a MS SQL database with .NET SQL Data Provider in ASP.NET

 DETAILS  <%@ import namespace="system.data.sqlclient" %><Script...

Query MySQL Database in PHP

DETAILS<html><head><title>MySQL Test...

Powered by WHMCompleteSolution