Home All Groups Group Topic Archive Search About

Question regarding Shared Functions or Subs

Author
20 Nov 2006 11:45 PM
Patriot
I wonder if it is threadsafe to have a Shared Function or Sub like
this:

Public Class Data1
    Public Shared Function Query1(Byref sCnxn as String, Byval sSql As
String) As DataTable
        Dim oCnxn As New SqlConnection(sCnxn)
        Dim oCmd As New SqlCommand(sSql, oCnxn)
        Dim oDs As New DataSet

        ' Mark the Command as a SPROC
        oCmd.CommandType = CommandType.Text

        oCnxn.Open()
        Dim oDa As SqlDataAdapter = New SqlDataAdapter(oCmd)
        oDa.Fill(oDs, "result")

        oCmd.Dispose()
        oCnxn.Close()

        Dim dt As DataTable = oDs.Tables("result").Copy
        oDs.Clear()
        oDs = Nothing
        oDa = Nothing

        Return dt
    End Function
End Class

Will I have any problem with multiple concurrent web requests?

Thanks

Author
21 Nov 2006 6:14 AM
Mattias Sjögren
>Will I have any problem with multiple concurrent web requests?

I don't tnhink so, you're not using any shared state as far as I can
see.


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
21 Nov 2006 5:48 PM
Patriot
Thank you for your feedback Mattias.

I was a bit worried that the connection will be closed unexpectedly. I
guess it'll be alright since none of the variables or parameters are
shared.

Thanks again.

On Nov 20, 10:14 pm, Mattias Sjögren
<mattias.dont.want.s***@mvps.org> wrote:
Show quote
> >Will I have any problem with multiple concurrent web requests?I don't tnhink so, you're not using any shared state as far as I can
> see.
>
> Mattias
>
> --
> Mattias Sjögren [C# MVP]  mattias @ mvps.orghttp://www.msjogren.net/dotnet/|http://www.dotnetinterop.com
> Please reply only to the newsgroup.

AddThis Social Bookmark Button