S
Stevie_mac
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.MANAGEMENT"))
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.MANAGEMENT"))