Code for accessing Oracle through oledb in ASP

Source: Internet
Author: User
System Environment:
1. Operating System: Windows 2000
2. Database: Oracle 8i R2 (8.1.6) for NT Enterprise Edition
3. installation path: C: \ oracle

Access Method:

1. Connect to SQL * Plus
Log On As A system/Manager User,
SQL> conn system/Manager

Create a new user, such as user1/pass1, and grant connect and resource permissions.
SQL> grant connect, resource to user1 identified by pass1;

SQL> conn user1/pass1
SQL> Create Table Test (a date );

The instance name of the Oracle database, in this example: oradb
Oracle username, for example, user1
Oracle host string: oradb

Tnsnames. ora File

Oradb =
(Description =
(Address_list =
(Address = (Protocol = TCP) (host = 192.1.1.1) (Port = 1521 ))
)
(CONNECT_DATA =
(SERVICE_NAME = oradb)
)
)

2. Create test. asp in the IIS default WWW directory and use notebook to edit it. Enter the followingCode
<%
Set conn = server. Createobject ("ADODB. Connection ")
DNS = "provider = oraoledb. oracle.1; persist Security info = true; user id = user1; Password = pass1; Data Source = oradb"
Conn. Open DNS

SQL = "insert into test (a) values (sysdate )"
Set rsw.conn.exe cute (SQL)

Set rs = nothing
Conn. Close
Set conn = nothing
%>

<%
Set conn = server. Createobject ("ADODB. Connection ")
DNS = "provider = oraoledb. oracle.1; persist Security info = true; user id = user1; Password = pass1; Data Source = oradb"
Conn. Open DNS

SQL = "select to_char (A, 'hh24: MI: ss') from test"
Set rsw.conn.exe cute (SQL)

Do While (not Rs. EOF)
%>
<Table border = 1>
<Tr> <TD> <% = Rs. Fields (0). Value %> </font> </TD>
</Tr>
<%
Rs. movenext
Loop

Rs. Close
Set rs = nothing
Conn. Close
Set conn = nothing
%>

3. Open a browser window and enter the following address to view the running result. You can press F5 to refresh the display result.

Http: // localhost/test. asp

Summary:
With the above code, you can save the trouble of creating ODBC and improve the efficiency.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.