VB.NET program, Local Access Database
My program is generating this error -:
DisconnectedContext was detected
Message: Transition into COM context 0x676010 for this RuntimeCallableWrapper failed with the following error: System call failed. (Exception from HRESULT: 0x80010100 (RPC_E_SYS_CALL_FAILED)). This is typically because the COM context 0x676010 where this RuntimeCallableWrapper was created has been disconnected or it is busy doing something else. Releasing the interfaces from the current COM context (COM context 0x675ea0). This may cause corruption or data loss. To avoid this problem, please ensure that all COM contexts/apartments/threads stay alive and are available for context transition, until the application is completely done with the RuntimeCallableWrappers that represents COM components that live inside them.
The error started occuring after I added a second call to the database inside a loop.
The program I wrote loops through all items in a database.
It sums up the total number of items sold (located in one table) in one query, then in another query it sums up the total number of items on a Credit Memo -
so that the number of items on the credit memo can be subtracted from the total number of items sold.
Below is how it looks -
"iis" = integer (inventory items sold)
"cms" = integer (credit memo sold)
sql2 = "select sum(InvoiceLineQuantity) as QSold from InvoiceLine where txnDate <= #" & newStart & "# and txnDate >= #" & newEnd & "# and InvoiceLineItemRefFullName = '" & ds.Tables(0).Rows(x).Item("FullName") & "'"
da2 = New OleDbDataAdapter(sql2, cn)
ds2 = New DataSet()
If ds2.Tables(0).Rows(0).Item("QSold").Equals(System.DBNull.Value) Then
iis = 0
iis = ds2.Tables(0).Rows(0).Item("QSold").ToString()
'Credit memo section (added to subtract item returns for accurate total sales)
sql2 = "select sum(CreditmemoLineQuantity) as CMSold from CreditmemoLine where txnDate <= #" & newStart & "# and txnDate >= #" & newEnd & "# and CreditMemoLineItemRefFullName = '" & ds.Tables(0).Rows(x).Item("FullName") & "'"
da3 = New OleDbDataAdapter(sql2, cn)
ds3 = New DataSet()
If ds3.Tables(0).Rows(0).Item("CMSold").Equals(System.DBNull.Value) Then
cms = 0
cms = ds3.Tables(0).Rows(0).Item("CMSold")
After the code runs, I subtract "cms" from "iis" to get "totalSales"
this code loops for each item from a specific vendor. Some vendors have 20 items, our biggest vendor has 800+ items. The error happens when I run the 800+ item vendor.
I'm a self taught programmer, so perhaps i'm going about this the wrong way - but I don't understand how a COM error happens - or how it could be related to the database calls. But, since the report ran just fine prior to me adding the credit memo section, that's what must be causing the error.
Can anyone provide any insight into what might be causing the error, or what I can do to prevent it? The compiler did not give me a pin-point spot or line number for the error...
Thanks for your help!