English 中文(简体)
VB的结晶体连接。 NET
原标题:Closing Oracle connection in VB.NET

在我的节目中,我用多个地点向Oracle数据库开放连接,通过一个储存的程序读到一些线,把我作为 cur,把他们带入一个IDataReader,关闭联系并接下去。

现在,一切工作都在关闭连接点前功尽弃。 我在观察通过ToAD为Oracle向数据库开放的链接,我发现,数据库似乎在我说过m_Connection之后保持了连接。 近和<代码>m_Connection。 处置

I use Oracle.DataAccess and get an error after a short time, that there are to many connections. I debuged my session and made sure, that vb performs the close() command and it does it, but the database not. Anyone got an idea how to fix this?

问题回答

在Net,你需要把Try/Catch/Finally栏的数据库连接起来,并总是关闭最后一节的链接。 这个名称为<代码>Using的栏目有短处。 这意味着保持某种联系(正如你似乎正在做的那样)几乎总是错失。 该网络得到优化,从而能够更好地为每个查询点建立一个新的连接和指挥物体。

数据检索者很少是特别的:如果你把数据检索器从使用块中回收,在数据检索完成之前可以关闭链接。 在C#中,我通常会与一名继承人(收益回报)讨论这个问题。 自VB以来。 对这一构件缺乏支持,我可能使用“行动”(Of IDataRecord)

Public Sub MyOracleQuery(ByVal id As Integer, ByVal ProcessRecord As Action(Of IDataRecord))
    Dim sql As String = "SELECT <columns> FROM MyTable WHERE ID= @Id"
    Using cn As New OracleConnection("connection string"), _
          cmd As New OracleCommand(sql, cn)

        cmd.Parameters.Add("@Id", SqlDbTypes.Int).Value = id
        cn.Open()

        Using (rdr As IDataReader = cmd.ExecuteReader())
            While rdr.Read()
                ProcessRecord(rdr)
            End While
        End Using
    End Using
End Sub

You can now pass an anonymous method to this code when you call it:

Dim id As Integer
If Integer.TryParse(IDTextBox.Text, id) Then
    MyOracleQuery(id, _
        Function(r)
              #... Do something with each "r" here
        End Function _
    )
Else
      # Complain to user about invalid ID
End If

请注意,这需要视力演播室2010年第4号,用于双向匿名方法。 对于旧的平台,你希望宣布这一方法。





相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签