在ASP中通过oo4o连接Oracle数据库的例子

下面这段代码能够显示,当前用户所能够看到的所有的用户和表,有兴趣的, 可以把每个表的内容加上

 1   
 2Dim objOraSession,objOraDb   
 3Dim strDbUser,strDbPwd,strDbConn   
 4Call ConnectDB()   
 5Sub ConnectDB()   
 6'连接数据库   
 7On Error Resume Next   
 8strDbUser = "tmpUser" '连接用户名   
 9strDbPwd = "rt45ps1w" '用户密码   
10strDbConn = "sun450" '连接字符串   
11Set objOraSession = Server.CreateObject("OracleInProcServer.XOraSession")   
12Set objOraDB = objOraSession.OpenDatabase(strDbConn,strDbUser & "/" & strDbPwd,0)   
13If Err.Number>0 then   
14Response.Write "

<font color="red">错误 :" &amp; err.description &amp; "</font>

 1"   
 2response.end   
 3End if   
 4End Sub   
 5Sub EndDB()   
 6Set objOraDB = Nothing   
 7Set objOraSession = Nothing   
 8End Sub   
 9Function getTableList(str)   
10Dim strSql,strTmp   
11Dim objRs   
12strSql = "Select at.table_name as tname,au.username as uname from all_tables at,all_users au Where au.username=at.owner order by au.username"   
13Set objRs = objOraDb.DbCreateDynaset(strSql,0)   
14While Not objRs.Eof   
15strA = objRs("uname") & "." & objRs("tname")   
16If str=strA then   
17strTmp = strTmp & "

<option selected="">" &amp; strA &amp; "</option>

1"   
2Else   
3strTmp = strTmp & "

<option>" &amp; strA &amp; "</option>

1"   
2End if   
3objRs.MoveNext   
4Wend   
5Set objRs = Nothing   
6getTableList = strTmp   
7End Function   
1<form action="index.asp" method="POST" name="form1" target="main">
2<table align="center" border="0" width="100%">
3<tr><td>   
4All Tables : <select name="tb">   

=getTableList(tblName)

1</select>
2<input name="submitc" type="hidden" value="view"/>
3<input name="submit" type="submit" value="View Data"/> <font color="red">(```
4=strDbUser &amp;amp; "/" &amp;amp; strDbPwd &amp;amp; "@" &amp;amp; strDbConn
5```)</font>
6</td></tr>
7</table>
8</form>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus