473,378 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Is shared safe in this example?

Hi all, quick question - I need a bit of clarity.

If I have a public class with only Public Shared functions in it, in an APS.NET web app (for common procedures) is it
safe (since multiple web pages, can at any time access the code within)

Example below - a simple routine that fills a dropdownlist or list. Would it be safe being accessed at multiple times by
the APSX pages? I think so, but I need an a more knowledgeable opinion.

Public Class MyUtils
Public Shared Function FillList(ByVal objList As Object, ByVal sSql As String, ByVal sConnection As String) As
Boolean
Dim dr As OleDb.OleDbDataReader, Li As ListItem
Dim cn As New OleDb.OleDbConnection(sConnection)
Dim cmd As OleDb.OleDbCommand
Try
cn.Open()
cmd = New OleDb.OleDbCommand(sSql, cn)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
Li = New ListItem
Li.Text = dr(0)
Li.Value = dr(1)
objList.Items.Add(Li)
End While
Catch ex As Exception
Stop
Return False
Finally
cmd.Dispose()
If dr Is Nothing = False Then dr.Close()
cn.Close()
End Try
Return True
End Function
End Class

Usage...
FillList(cmbListOfNames, AppSettings("SQL.PEOPLE"),AppSettings("CONSTRING.M ANAGEMENT"))
Nov 20 '05 #1
0 1281

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Paul Wu | last post by:
From what I understand, in ASP.NET, each HTTP requests is serviced by a separate thread. So if my code uses a static Class with shared members and properties, I can manage concurrent access by using...
11
by: dee | last post by:
OleDbCommand class like many .NET classes has the following description in its help file: "Thread Safety Any public static (Shared in Visual Basic) members of this type are safe for...
15
by: Rob Nicholson | last post by:
A consequence of the ASP.NET architecture on IIS has just hit home with a big thud. It's to do with shared variables. Consider a module like this: Public Module Functions Public GlobalName As...
10
by: Stevie_mac | last post by:
Hi all, quick question - I need a bit of clarity. If I have a public class with only Public Shared functions in it, in an APS.NET web app (for common procedures) is it safe (since multiple web...
4
by: Gregory Gadow | last post by:
I've cobbled together a PrinterClass that takes a text file and dumps it to a printer. The app using is has multiple threads, all of which need access to a shared instance. Can someone point me to...
5
by: Simon | last post by:
Hi all, We have an ASP.NET 1.1 application running on IIS6 on Server 2003. Most of the base objects we are using in this application are taken from a windows application also written by us. We...
4
by: herbert | last post by:
I am coding a dozen "background" realtime apps for factory automation in .NET 2.0. The apps need to share a common memory as there are lots of variables to be shared (and synchronized of...
15
by: Laser Lu | last post by:
I was often noted by Thread Safety declarations when I was reading .NET Framework Class Library documents in MSDN. The declaration is usually described as 'Any public static (Shared in Visual...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.