Database: Throw when Connection is nothing in MaybeGetTransaction

This commit is contained in:
Jonathan Jenne 2021-05-17 10:39:38 +02:00
parent 4c78e6e5a7
commit d32a14c4d8
2 changed files with 19 additions and 7 deletions

View File

@ -134,6 +134,8 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Monitor", "GUIs.Monitor\Mon
EndProject EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "MonoRepoUtils", "ConfigCreator\MonoRepoUtils.vbproj", "{9D4AC920-C78E-41C3-994E-91690FF79380}" Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "MonoRepoUtils", "ConfigCreator\MonoRepoUtils.vbproj", "{9D4AC920-C78E-41C3-994E-91690FF79380}"
EndProject EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Database.Cached", "Database.Cached\Database.Cached.vbproj", "{E0DC883D-FAE1-4103-B2BA-043EBE697B09}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -356,6 +358,10 @@ Global
{9D4AC920-C78E-41C3-994E-91690FF79380}.Debug|Any CPU.Build.0 = Debug|Any CPU {9D4AC920-C78E-41C3-994E-91690FF79380}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D4AC920-C78E-41C3-994E-91690FF79380}.Release|Any CPU.ActiveCfg = Release|Any CPU {9D4AC920-C78E-41C3-994E-91690FF79380}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D4AC920-C78E-41C3-994E-91690FF79380}.Release|Any CPU.Build.0 = Release|Any CPU {9D4AC920-C78E-41C3-994E-91690FF79380}.Release|Any CPU.Build.0 = Release|Any CPU
{E0DC883D-FAE1-4103-B2BA-043EBE697B09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E0DC883D-FAE1-4103-B2BA-043EBE697B09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E0DC883D-FAE1-4103-B2BA-043EBE697B09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E0DC883D-FAE1-4103-B2BA-043EBE697B09}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -415,6 +421,7 @@ Global
{65EFB268-C0E0-40C1-8981-9F70DEE5C74A} = {F98C0329-C004-417F-B2AB-7466E88D8220} {65EFB268-C0E0-40C1-8981-9F70DEE5C74A} = {F98C0329-C004-417F-B2AB-7466E88D8220}
{E24E8D40-0361-4C07-8FAE-3621DE316E70} = {8FFE925E-8B84-45F1-93CB-32B1C96F41EB} {E24E8D40-0361-4C07-8FAE-3621DE316E70} = {8FFE925E-8B84-45F1-93CB-32B1C96F41EB}
{9D4AC920-C78E-41C3-994E-91690FF79380} = {8FFE925E-8B84-45F1-93CB-32B1C96F41EB} {9D4AC920-C78E-41C3-994E-91690FF79380} = {8FFE925E-8B84-45F1-93CB-32B1C96F41EB}
{E0DC883D-FAE1-4103-B2BA-043EBE697B09} = {3E2008C8-27B1-41DD-9B1A-0C4029F6AECC}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C1BE4090-A0FD-48AF-86CB-39099D14B286} SolutionGuid = {C1BE4090-A0FD-48AF-86CB-39099D14B286}

View File

@ -74,6 +74,10 @@ Public Class MSSQLServer
End Function End Function
Private Function MaybeGetTransaction(Connection As SqlConnection, Mode As TransactionMode, Transaction As SqlTransaction) As SqlTransaction Private Function MaybeGetTransaction(Connection As SqlConnection, Mode As TransactionMode, Transaction As SqlTransaction) As SqlTransaction
If Connection Is Nothing Then
Throw New ArgumentNullException("Connection")
End If
If Mode = TransactionMode.NoTransaction Then If Mode = TransactionMode.NoTransaction Then
Return Nothing Return Nothing
ElseIf Mode = TransactionMode.ExternalTransaction Then ElseIf Mode = TransactionMode.ExternalTransaction Then
@ -176,14 +180,15 @@ Public Class MSSQLServer
End Try End Try
End Function End Function
''' <summary>
''' This Function intentionally has no try..catch block to have any errors caught outside
''' </summary>
''' <param name="Connection"></param>
''' <returns></returns>
Private Function OpenSQLConnection(Connection As SqlConnection) As SqlConnection Private Function OpenSQLConnection(Connection As SqlConnection) As SqlConnection
Try If Connection.State = ConnectionState.Closed Then
If Connection.State = ConnectionState.Closed Then Connection.Open()
Connection.Open() End If
End If
Catch ex As Exception
_Logger.Error(ex)
End Try
Return Connection Return Connection
End Function End Function