Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / November 2006

Tip: Looking for answers? Try searching our database.

Question regarding Shared Functions or Subs

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patriot - 20 Nov 2006 23:45 GMT
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
Mattias Sjögren - 21 Nov 2006 06:14 GMT
>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

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Patriot - 21 Nov 2006 17:48 GMT
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.

> >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.
[quoted text clipped - 4 lines]
> Mattias Sjögren [C# MVP]  mattias @ mvps.orghttp://www.msjogren.net/dotnet/|http://www.dotnetinterop.com
> Please reply only to the newsgroup.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.