Hi,
I went through the code last night and made sure that everything is disposed of. I have added a dispose function for the connection object which I am going to test now.
the webservice code creates a business object (not sure if it should be disposed)
the business object creates a data object (not sure if it should be disposed)
Web service:
Public Class GRV
Inherits System.Web.Services.WebService
Dim bus As New GRBussiness
<webmethod()> _
Public Function HelloWorld(ByVal strShippingLabel As String, ByVal strBoxStatus As String, ByVal strWeekNo As String) As Boolean
Dim ShippingLabelisFound As Boolean = False
Try
ShippingLabelisFound = bus.Scan_MarkShippingLabelsFound(strShippingLabel, strWeekNo, strBoxStatus)
Return ShippingLabelisFound
Catch ex As Exception
Return False
End Try
End Function
End Class
data layer - is a class that is instantiated in the business layer
Dim data As New DataLayer - instantiated in bus object
Sub MakeConnect_GRV()
GRVcon.ConnectionString = "Data Source=192.168.10.24\BDMS;" & _
"Initial Catalog=FLATPAN_STOCK;" & _
"User ID=flatpan;" & _
"Password="password"
Try
GRVcon.Open()
Catch ex As Exception
'MessageBox.Show(ex.Message)
End Try
End Sub
Sub DestroyConnection()
GRVcon.Dispose()
End Sub
Below is the code I use to do the actual update. This is part of a class that gets called in the webserivice code asmx.vb.
Dim bus As New GRBussiness 'Not sure if I am disposing of this correctly?
Function Scan_MarkShippingLabelsFound(ByVal ScanndedShippingLabel As String, ByVal WeekLookup As String, ByVal strBoxStatus As String) As Boolean
Try
Dim ShippingLabebelStatusIsUpdated As Boolean
Dim strUpdate As String = ""
If ScanndedShippingLabel <> "" And strBoxStatus <> "" Then
If WeekLookup = "" Then
strUpdate = "Update PackingLists " & _
"Set BoxStatus=@BoxStatus, ScanDate=@ScanDate " & _
"WHERE ShippingLabel='" & ScanndedShippingLabel & "' " & _
"AND BoxStatus='" & strBoxStatus & "'"
Else
strUpdate = "Update PackingLists " & _
"Set BoxStatus=@BoxStatus, ScanDate=@ScanDate " & _
"WHERE ShippingLabel='" & ScanndedShippingLabel & "' " & _
"AND WeekNo='" & WeekLookup & "' AND BoxStatus='" strBoxStatus & "'"
End If
If data.grvConnection.State = ConnectionState.Closed Then _
data.MakeConnect_GRV()
Dim cmdEdit As New SqlClient.SqlCommand(strUpdate, data.grvConnection)
cmdEdit.Parameters.Add("@BoxStatus", SqlDbType.VarChar,50).Value="FOUND"
cmdEdit.Parameters.Add("@ScanDate", SqlDbType.VarChar,50).Value=Date.Now
Dim IsRowadded As Integer = 0 'Variable to check if row is added
If data.grvConnection.State = ConnectionState.Closed Then data.grvConnection.Open()
IsRowadded = cmdEdit.ExecuteNonQuery()
If IsRowadded = 1 Or IsRowadded > 1 Then
ShippingLabebelStatusIsUpdated = True
Else
ShippingLabebelStatusIsUpdated = False
End If
cmdEdit.Dispose()
data.DestroyConnection() ' just added this now and will test...
End If
Return ShippingLabebelStatusIsUpdated
Catch ex As Exception
'MessageBox.Show("GRBusiness:- MarkShippingLabelsFound: " & ex.Message)
Return False
End Try
End Function