Connecting to Oracle using ODBC and a DSN Connection

Source Code

the example below uses a DSN connection setup on the IIS server called ora12c, which uses an ODBC driver and links to the Oracle 12c database. Also see the OLE and OO40 examples as alternative DSNless methods.

<html>
<head>
<title>Connecting to an Oracle database using ODBC and DSN connection</title>
</head>
<body>

<%

SET myConn=SERVER.createobject("adodb.connection")
myConn.Open "DSN=ora12c;" & _
"Uid=myOracleUsername;" & "Pwd=myOraclePassword"

SQLStr="SELECT empno, ename, deptno FROM Emp ORDER BY deptno, ename"
SET result=myConn.execute(SQLStr)
IF NOT result.EOF thEN
  response.write("<h2>Oracle ASP Example</h2>")
  response.write("<p>Connecting to the Oracle11g database using ODBC & a DSN connection</p>")
  response.write("<table BORDER=3 BGCOLOR=#0099CC><tr><th>Employee No</th>" & _
    "<th>Name</th><th>Department No</th>")
  WHILE NOT result.EOF
    response.write("<tr><td>" & result("empno") & "</td>")
    response.write("<td>" & result("ename") & "</td>")
    response.write("<td>" & result("deptno") & "</td></tr>")
    result.movenext()
  WEND
  response.write("</table>")
ELSE
  response.write("<p>Error retrieving Employee data!!</p>")
END IF

%>
</body>
</html>

Click here to run the program