Imports System.Data.SqlClient
Imports CSharp.Core
Public Class DBProvider
Public Sub LogSQLMessages(ByVal sender As Object, ByVal e As SqlInfoMessageEventArgs)
Logger.prn("SQLMessage:" & e.ToString)
End Sub
Private Shared youBillConn As String = ConfigurationManager.ConnectionStrings("conn").ConnectionString
Public Function ExecuteScalar(ByVal spname As String, ByVal ParamArray sparams() As Object) As Object
Dim sqlc As New SqlConnection(youBillConn)
Try
AddHandler sqlc.InfoMessage, AddressOf LogSQLMessages
'sqlc.FireInfoMessageEventOnUserErrors = True
sqlc.Open()
Return SqlHelper.ExecuteScalar(sqlc, spname, sparams)
Catch ex As SqlClient.SqlException
Dim erix As Integer = ex.Message.IndexOf("MSIEX:[[")
Dim eree As Integer = ex.Message.IndexOf("]]")
If erix >= 0 And eree > 0 And eree > erix Then
Assertions.Throw(ex.Message.Substring(erix + 8, (eree - erix) - 8))
Else
Logger.prn(ex)
Throw ex
End If
Return Nothing
Catch allex As Exception
Logger.prn(allex)
Throw allex
Finally
sqlc.Close()
End Try
End Function
End Class
more...
No comments:
Post a Comment