G
Guest
When I implement my DB classes/DAL layer, why shouldn't I make the methods
(in VB) 'shared'?
Forget the other questions I have right now about whether to put in that
finally block, etc. Why not make the function shared? Why bother have the
class be instatiated and then the method invoked- this method could be
shared, it really has no state, right?
-Dan R
For example, let's say I've got the following method of the DAL class
(you've seen something like this)
Public Function GetSqlDataReader(ByVal strSQL As String) As SqlDataReader
Dim con As SqlConnection = New SqlConnection(DBAccess.SQL_CONN_STR)
Dim cmd As SqlCommand = New SqlCommand(strSQL, con)
Dim dr As SqlDataReader
Try
con.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection) 'We do
this so that a .close on the SqlDataReader will close the connection.
Return dr
Catch ex As Exception
Throw ex 'Rethrows it. I don't need to put the ex, I don't
think, incidentally
Finally 'From
http://www.dotnet247.com/247reference/msgs/8/40569.aspx is this overkill?
If (Not dr Is Nothing) Then 'It was left open
dr.Close()
End If
End Try
End Function
(in VB) 'shared'?
Forget the other questions I have right now about whether to put in that
finally block, etc. Why not make the function shared? Why bother have the
class be instatiated and then the method invoked- this method could be
shared, it really has no state, right?
-Dan R
For example, let's say I've got the following method of the DAL class
(you've seen something like this)
Public Function GetSqlDataReader(ByVal strSQL As String) As SqlDataReader
Dim con As SqlConnection = New SqlConnection(DBAccess.SQL_CONN_STR)
Dim cmd As SqlCommand = New SqlCommand(strSQL, con)
Dim dr As SqlDataReader
Try
con.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection) 'We do
this so that a .close on the SqlDataReader will close the connection.
Return dr
Catch ex As Exception
Throw ex 'Rethrows it. I don't need to put the ex, I don't
think, incidentally
Finally 'From
http://www.dotnet247.com/247reference/msgs/8/40569.aspx is this overkill?
If (Not dr Is Nothing) Then 'It was left open
dr.Close()
End If
End Try
End Function