ASP 中通过OLEDB访问 Oracle 的代码
系统环境:
1、操作系统:Windows 2000
2、数据库:Oracle 8i R2 (8.1.6) for NT 企业版
3、安装路径:C:\ORACLE
访问方法:
1、连入SQL*Plus
以system/manager用户登录,
SQL> conn system/manager
创建新的用户:如user1/pass1,赋予connect,resource权限。
SQL> grant connect,resource to user1 identified by pass1;
SQL> conn user1/pass1
SQL> create table test(a date);
Oracle数据库的实例名,本例:oradb
Oracle用户名,本例:user1
Oracle主机字符串:oradb
tnsnames.ora文件中
ORADB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.1.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = oradb)
)
)
2、在IIS默认WWW目录下创建test.asp,用notebook编辑,输入以下代码
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 rs=conn.execute(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 rs=conn.execute(SQL)
do while (not rs.eof)
%
rs.movenext
loop
rs.close
set rs=nothing
conn.close
set conn=nothing
%
3、打开一个浏览器窗口,输入以下地址来查看运行结果,可以通过不断的按F5键来刷新显示结果
http://localhost/test.asp