sql-server - 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
解决方案
推荐阅读
- mysql - 子查询和公用表表达式
- javascript - 无法在javascrit中获得两个数字的总和
- python - 当我调用一个跳过链接列表中节点的函数时,为什么输出是一个空列表?
- java - 根据条件调用实现类
- android - 在我的自定义后端使用 Firebase ID 令牌进行身份验证的安全问题
- reactjs - 如何改变波形值three.js
- android - 反应本机 callkeep 模块 - 无法为某些 android 设备设置权限
- random - 我想在每次刷新 html 时在 html 页面中打印一个随机数
- wso2 - 我们如何为 wso2iot. 应用 i18n?
- apache-kafka - 删除cleaner-offset-checkpoint文件强制压缩是否安全?