我使用sqldatasource在asp.net中连接oracle数据库,这是我的连接字符串
<add name="ConnectionString3" connectionString="Data Source=sml; User ID=sml; Password=sml; Unicode=True; Pooling=False;" providerName="System.Data.OracleClient"/>
我打开连接,在做了选择后我关闭了连接。问题是,当我浏览数据库的会话时,那里存在两个锁定的会话。他们不清楚,直到我关闭asp.net server.can任何人指导我什么是asp.net连接oracle db的正确方法,然后管理连接清除后连接数据库。我的意思是我怎么样查询后可以从数据库中注销。
更新
Dim con = New OleDbConnection("Data Source=sml; User ID=sml; Password=sml; provider=OraOLEDB.Oracle; Pooling=false")
Try
con.Open()
Dim cmd As New OleDbCommand("SELECT UPDTIME, YBAL_J, SCROLL_J, PENDING_PMT_J, YBAL_B, SCROLL_B, PENDING_PMT_B, CR_DT, OUT_BAL_J, OUT_BAL_B,SUGAR_J,CANE_CRUSH_J,RECOVERY_J,ETHANOL_J,SHEET_J,SUGAR_B,CANE_CRUSH_B,RECOVERY_B,ETHANOL_B FROM CMS20122013.V_DASH_LABELS@CMS", con)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds)
Label1.Text = ds.Tables(0).Rows(0)(0).ToString
Label5.Text = ds.Tables(0).Rows(0)(0).ToString
Label2.Text = ds.Tables(0).Rows(0)(1).ToString
Label3.Text = "Scroll Issued: " & ds.Tables(0).Rows(0)(2).ToString
Label4.Text = "Payment Pending: " & ds.Tables(0).Rows(0)(3).ToString
Label6.Text = ds.Tables(0).Rows(0)(4).ToString
Label7.Text = "Scroll Issued: " & ds.Tables(0).Rows(0)(5).ToString
Label8.Text = "Payment Pending: " & ds.Tables(0).Rows(0)(6).ToString
Label14.Text = ds.Tables(0).Rows(0)(7).ToString
GridView4.Columns(4).HeaderText = ds.Tables(0).Rows(0)(8).ToString
GridView9.Columns(4).HeaderText = ds.Tables(0).Rows(0)(9).ToString
GridView2.Columns(0).HeaderText = "Crushing [" & ds.Tables(0).Rows(0)(11).ToString & "]"
GridView7.Columns(0).HeaderText = "Crushing [" & ds.Tables(0).Rows(0)(16).ToString & "]"
con.Close()
con.Dispose()
Catch ex As Exception
con.Close()
con.Dispose()
Finally
con.Close()
con.Dispose()
End Try
答案 0 :(得分:1)
您是否尝试过使用c#“#”语法?
using(var connection = new OracleConnection("some connection string"))
{
connection.Open();
//do stuff with connection
}
此处有更多详情:http://msdn.microsoft.com/en-us/library/yh598w02(v=vs.100).aspx