首页 > 解决方案 > VB.net web 服务,如果我在最后调用退出函数,我还需要关闭/处置吗?

问题描述

我有一个多年前编写的 VB.net Web 服务,我“认为”可能有一些问题。

我真的不是 VB.net 人,对 Close Dispose 协议的了解有限。阅读让我得到以下信息,但我仍然不清楚。

https://stackoverflow.com/questions/4439409/open-close-sqlconnection-or-keep-open

我主要关心的是 MS SQL 数据库的处理,潜在的锁定等。见过一些。

以下代码是一个函数(截断代码)的一部分,但您会看到有许多“退出函数”行。

我假设“最终”代码不会被执行,因此不会执行关闭/处置等?在该退出函数之后,Web 服务处理返回到调用应用程序。

这是一个问题,没有处理“最后”的代码块(关闭/处置)?

如果是这样,我想删除 Exit Function 行将解决这个问题?

或者 .. 将在退出函数之前放置一个 CloseDbConnection() 也一样。

谢谢

                        ElseIf AppMode = "Update" Then
                        InPhoneGUID = db.updateInPhoneScanner(returnedUID, AppMode, New List(Of String)(New String() {tmpl1}))

                        If Not InPhoneGUID = "" Then
                            r.Message = "PhoneScanner Templates Updated"
                            '   resultList.Add(r)    ' Doubling up on the Returned info ?
                            r.GenUID = InPhoneGUID
                            resultList.Add(r)
                            Return GetResponseTextForMobile(resultList)
                            Exit Function
                        Else
                            r.Message = "error 1,PhoneScanner Update Failed"
                            resultList.Add(r)
                            Return GetResponseTextForMobile(resultList)
                            Exit Function
                        End If

                        _Logger.Info("=== Invalid Account Type for PHONESCANNER ===")
                        r.Message = "error 1,Account Addition Inavild Type"
                        resultList.Add(r)
                        Return GetResponseTextForMobile(resultList)
                        Exit Function
                    End If


                End If          ' End  ===========  MAINLINE ROUTINE

                _Logger.Info("=== Invalid MODE ===")
                r.Message = "error 1,Inavild Mode Sent"
                resultList.Add(r)
                Return GetResponseTextForMobile(resultList)
                Exit Function

            End If
        End If
    Catch ex As Exception
        _Logger.Error(ex)
    Finally
        db.CloseDbConnection()
        If fingerPrintHelper IsNot Nothing Then
            fingerPrintHelper.Dispose()
        End If

        db = Nothing
    End Try

db.CloseConnection 如下;

        Public Sub CloseDbConnection()
        Try
            mSqlconnection.Close()
            mSqlconnection.Dispose()
            mSqlconnection = Nothing
        Catch ex As Exception
            'Throw New Exception("CloseDbConnection : " & ex.Message)
        End Try
    End Sub

标签: sql-servervb.net

解决方案


推荐阅读