<%
'连接到数据库
set orasession=createobject("oracleinprocserver.xorasession")
set oradatabase=orasession.dbopendatabase("数据库实例名","用户名/密码",0)
strno=trim(request("userno"))
sqlstr="select name from abc where no='" &strno &"'"
Set rs_oracle = OraDatabase.DbCreateDynaset(sqlstr, cint(0))
if rs_oracle.eof or rs_oracle.bof then
else
response.write rs_oracle("name")
end if
%>
<form action="TEST.asp" target=_blank method=post name="xdmo">
<select size="1" name="userno" >
<option value=1 selected>-1-</option>
<option value=2>-2-</option>
<option value=3>-3-</option>
</select>
<input type="submit" name="Submit" value="查找">
</form>
打开安装目录D:\oracle\product\10.2.0\client_1\NETWORK\ADMIN文件夹下的tnsnames.ora文件,进行如下配置:
TOPTEST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.122.10.9)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = toptest)
)
)
在web.config文件中添加连接字符串,如:
<add
name="OracleConn"
connectionString="Data
Source=TOPTESTUser
ID=ds1Password=ds1Unicode=True"
providerName="System.Data.OracleClient"/>
如果程序与数据库在同一台计算机上,则可以用这一连接。
<add
name="OracleConn"
connectionString="Data
Source=10.100.1.9User
ID=ds1Password=ds1Unicode=True"
providerName="System.Data.OracleClient"/>
使用连接字符串访问数据库
public
static
readonly
string
connectionString
=
ConfigurationManager.ConnectionStrings["OracleConn"].ConnectionString
按照以上的步骤进行 *** 作,ASP.NET就能够成功地访问Oracle数据库
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)