這是一個奇怪的 - 我們有一個調用數據服務的winforms應用程序。最終用戶可以選擇當前的數據庫,並且只有其中一個數據庫有時會將此錯誤引發一次,所有其他數據庫無縫工作。Winforms - 服務處置對象錯誤
拋出的錯誤是
Cannot access a disposed object.
Object name: 'System.ServiceModel.Channels.ServiceChannel'.
和堆棧跟蹤
Server stack trace:
at System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrNotOpen()
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at HOA_Manager_Client_03.ServiceReference1.IService1.InsertDataHOA(String strSQL, String LineNo, String HOAID)
感謝
編輯 - 這是它如何被應用
Private Sub Accounting_Utilities_Prepayments_MovePrepaymentsToUnallocated(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim DGV As CustomControl.DGV = RFC(MainForm, "Prepayments_DGV")
Dim TotalRows As Integer = 0
Dim TotalBalance As Decimal = 0
For Each Row As DataGridViewRow In DGV.SelectedRows
Dim vBalance As Decimal = Row.Cells("Balance").Value
TotalBalance += vBalance
TotalRows += 1
Next
If TotalRows = 0 Then
TaskDialog.Show(MainForm, AppBoxWarning("Validation", "You have not selected any records to transfer from!", "Validation"))
Exit Sub
End If
Dim vConfirm As String = "You have selected " & TotalRows & " total records, and a total balance of $" & Format(TotalBalance, "###,##0.00") & " to transfer back!" & Environment.NewLine
vConfirm += "Once transferred the prepayment account will be deleted!" & Environment.NewLine
vConfirm += "Proceed with the transfer?"
If Not TaskDialog.Show(MainForm, AppBoxQuestion("Confirmation", vConfirm, "Proceed Confirmation")) = eTaskDialogResult.Yes Then
Exit Sub
End If
vService = New Service1Client
MainForm.Cursor = Cursors.WaitCursor
For Each Row As DataGridViewRow In DGV.SelectedRows
Dim vBalance As Decimal = Row.Cells("Balance").Value
Dim CreditName As String = Row.Cells("Creditor").Value
Dim PrepaymentID As Integer = Row.Cells("ID").Value
MainSS.Text = "Transfering balance for " & CreditName & "... Please wait..."
Application.DoEvents()
'Nominal Ledger in and out for audit trail
If vService Is Nothing Then
vService = New Service1Client
End If
strSQL = "INSERT INTO A_Nominal (Type, Ref, Details, Debit, Nominal_Code, Item_Date) VALUES ("
strSQL += "'JD', "
strSQL += "'Transfer', "
strSQL += "'Transfer to Debtors Control Account', "
strSQL += "'" & vBalance & "', "
strSQL += "'1103', "
strSQL += "'" & Format(Today, "yyyy-MM-dd") & "')"
If vService.InsertDataHOA(strSQL, "MainTabs_3 51002", Current_HOA_ID) = False Then
TaskDialog.Show(MainForm, AppBoxError("Error", "There was an error updating the records", "Update Error"))
Exit Sub
End If
strSQL = "INSERT INTO A_Nominal (Type, Ref, Details, Credit, Nominal_Code, Item_Date) VALUES ("
strSQL += "'JC', "
strSQL += "'Transfer', "
strSQL += "'Transfer from Prepayments', "
strSQL += "'" & vBalance & "', "
strSQL += "'1100', "
strSQL += "'" & Format(Today, "yyyy-MM-dd") & "')"
If vService.InsertDataHOA(strSQL, "MainTabs_3 51015", Current_HOA_ID) = False Then
TaskDialog.Show(MainForm, AppBoxError("Error", "There was an error updating the records!", "Update Error"))
Exit Sub
End If
'Control account in and out
strSQL = "INSERT INTO A_Control (Control_ID, C_Description, Debit) VALUES ("
strSQL += "'1103', "
strSQL += "'Transfer to Debtors Control Account', "
strSQL += "'" & vBalance & "')"
If vService.InsertDataHOA(strSQL, "MainTabs_3 51029", Current_HOA_ID) = False Then
TaskDialog.Show(MainForm, AppBoxError("Error", "There was an error updating the records!", "Update Error"))
Exit Sub
End If
strSQL = "INSERT INTO A_Control (Control_ID, C_Description, Credit) VALUES ("
strSQL += "'1100', "
strSQL += "'Transfer from Prepayments', "
strSQL += "'" & vBalance & "')"
If vService.InsertDataHOA(strSQL, "MainTabs_3 51038", Current_HOA_ID) = False Then
TaskDialog.Show(MainForm, AppBoxError("Error", "There was an error updating the records!", "Update Error"))
Exit Sub
End If
strSQL = "SELECT Customer_ID FROM A_Prepayments WHERE Prepayment_ID = " & PrepaymentID
Dim CustomerID As Integer = vService.ReturnScalarInteger(strSQL, Current_HOA_ID)
'Move into Sales Ledger
strSQL = "INSERT INTO A_Sales_Ledger (Credit, Paid, S_Description, Document_Date, Customer_ID, Type) VALUES ("
strSQL += "'" & vBalance & "', "
strSQL += "'N', "
strSQL += "'Transfer from prepayments', "
strSQL += "'" & Format(Today, "yyyy-MM-dd") & "', "
strSQL += "'" & CustomerID & "', "
strSQL += "'PT')"
If vService.InsertDataHOA(strSQL, "MainTabs_3 51053", Current_HOA_ID) = False Then
TaskDialog.Show(MainForm, AppBoxError("Error", "There was an error updating the records!", "Update Error"))
Exit Sub
End If
'Delete the prepayment record
strSQL = "DELETE A_Prepayments WHERE Prepayment_ID = " & PrepaymentID
If vService.InsertDataHOA(strSQL, "MainTabs 51063", Current_HOA_ID) = False Then
TaskDialog.Show(MainForm, AppBoxError("Error", "There was an error updating the records!", "Update Error"))
Exit Sub
End If
Next
MainSS.Text = "Data successfully transferred..."
Accounting_Utilities_Prepayments_LoadData()
Catch ex As Exception
EmailError(ex)
Finally
MainForm.Cursor = Cursors.Default
If Not vService Is Nothing Then
vService.Close()
vService = Nothing
End If
End Try
End Sub
看起來像有東西持有對這個對象的引用。檢查是否有任何靜態對象持有對您服務的引用。 – 2013-05-05 19:07:41
不希望看起來很厚(我的辯解是星期天),但不能調用ServiceModel的多個事件? – gchq 2013-05-05 19:19:31
那麼你沒有清楚地列出你的場景在這裏。另外你的問題並沒有清楚地告訴你如何使用你的服務。無論如何,我做了一個假設,並將其添加爲評論。 – 2013-05-05 19:23:08