I have a function in a VB.NET system that I use to run queries in DB. The function is Public Shared for the sake of simplicity. And there is the question whether competing access to function could generate problems.
This is user 'A' calls the function with a query and before the query is executed, user 'B' calls the same function with a different query. So this concurrent access can generate unexpected results?
Below the code:
Public Class ExecuteDB
Public Shared Function Execute(ByVal query As String) As DataSet
Dim ds As New DataSet
If query Is Nothing OrElse query = "" Then
Return ds
End If
Dim connectionString As String = ConfigurationManager.ConnectionStrings("CnString").ConnectionString
Using connection As New SqlConnection(connectionString)
Dim command As New SqlCommand(query, connection)
Try
Dim da As New SqlDataAdapter(command)
da.Fill(ds)
Catch ex As Exception
Throw ex
End Try
End Using
Return ds
End Function
End Class