這應該是很古老題目,不過要用的時候總是找不到,
做個記錄,把下方文字內容存成TEST.ASPX,即可測試是否能連線成功。
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<Script Language="VB" Runat="Server">
Sub Page_Load(Sender As Object, e As EventArgs)
Dim mySelectQuery As String = "select * from user_tables where tablespace_name is not null"
Dim myConnection As New OleDbConnection("Provider=ORAOLEDB.Oracle;Server=DBSRV_IP;Data Source=SID;User Id=DB_USER;password=DB_PASSWORD")
Dim myCommand As New OleDbCommand(mySelectQuery, myConnection)
myConnection.Open()
Dim myReader As OleDbDataReader = myCommand.ExecuteReader()
Try
While myReader.Read()
Response.Write(myReader.GetString(0) + ", " + myReader.GetString(1)+"<br>")
End While
Finally
' always call Close when done reading.
myReader.Close()
' always call Close when done reading.
myConnection.Close()
End Try
End Sub
</Script>
當myConnection.Close()執行後,在ORACLE DB的SESSION並不會馬上結束,大約在1分鐘後由.NET自動清除,這是類似 pool的執行概念。
沒有留言:
張貼留言