INTRODUCTION
This article discusses how to connect to an Oracle database by using a Microsoft Active Server Pages (ASP) page and Microsoft ActiveX Data Objects (ADO).
MORE INFORMATION
To connect to an Oracle database, you can create an ASP page that contains the following code.
Note
Make sure that the connect string has a valid user ID and password and that the SQL statement references a valid table.
<%@ Language=VBScript %>
<html>
<head>
<title>Oracle Test</title>
</head>
<body>
<center>
<%
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=MSDAORA;Data Source=<Your_TNSNames_Alias>;User Id=<userid>;Password=<password>;"
Set objRs = objConn.Execute("SELECT * FROM DEMO.EMPLOYEE")
Response.Write "<table border=1 cellpadding=4>"
Response.Write "<tr>"
For I = 0 To objRS.Fields.Count - 1
Response.Write "<td><b>" & objRS(I).Name & "</b></td>"
Next
Response.Write "</tr>"
Do While Not objRS.EOF
Response.Write "<tr>"
For I = 0 To objRS.Fields.Count - 1
Response.Write "<td>" & objRS(I) & "</td>"
Next
Response.Write "</tr>"
objRS.MoveNext
Loop
Response.Write "</table>"
objRs.Close
objConn.Close
%>
</center>
</body>
</html>
<html>
<head>
<title>Oracle Test</title>
</head>
<body>
<center>
<%
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=MSDAORA;Data Source=<Your_TNSNames_Alias>;User Id=<userid>;Password=<password>;"
Set objRs = objConn.Execute("SELECT * FROM DEMO.EMPLOYEE")
Response.Write "<table border=1 cellpadding=4>"
Response.Write "<tr>"
For I = 0 To objRS.Fields.Count - 1
Response.Write "<td><b>" & objRS(I).Name & "</b></td>"
Next
Response.Write "</tr>"
Do While Not objRS.EOF
Response.Write "<tr>"
For I = 0 To objRS.Fields.Count - 1
Response.Write "<td>" & objRS(I) & "</td>"
Next
Response.Write "</tr>"
objRS.MoveNext
Loop
Response.Write "</table>"
objRs.Close
objConn.Close
%>
</center>
</body>
</html>
APPLIES TO
- | Microsoft Active Server Pages 4.0 |
- | Microsoft Internet Information Services 6.0 |
- | Microsoft Data Access Components 2.8 |
No comments:
Post a Comment