all groups > dotnet remoting > june 2005 >
You're in the

dotnet remoting

group:

Error Using Remoting, System.OutOfMemoryException anyone ever seen this?


Error Using Remoting, System.OutOfMemoryException anyone ever seen this? Microsoft News
6/29/2005 9:38:09 AM
dotnet remoting:
Greetings,

I am working on a remoting project and have hit one road block after
another. I am sure it is because I do not know everything about remoting.

My latest problem is that I finally got the remoting to work they way I
want. I have a window service setup on my server, it is exposing a datatier
set of DLLs that implements a framework which will make calls to the
database and return a dataset back across the internet to the user business
tier DLL where the data will be used. It works great when the data set is
small. However when I return a large amount of information it fails with
the following problem:

"System.OutOfMemoryException: Exception of type System.OutOfMemoryException
was thrown.

Server stack trace:


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 MHSData.CBillingData.GetBillingItemsDS(Int64 plBillID, Int32 pnPAID,
Int32 pnUserID, Int16 piView)
at MHSBusiness.CBillables.GetBillableItems(Int64 plBillID, Int32 pnPAID,
Int32 pnUserID, Filtering peView) in C:\Dev\Dev .Net\R&D
Code\Remoting\DataTierPrototype\MHSBusiness\CBillables.vb:line 63"

So to provide some more details, I have a GUI that creates an object from a
class in my business tier. From this object I make a call to get data from
the database. This routine is the Get in the business tier. As you can see
I have a setup a call that you can pass the datatier routine name to
"CBillingData", and that will go out to a factory, and pull the datatier
object back across the internet using remoting.

Public Function GetBillableItems(Optional ByVal plBillID As Long = 0,
Optional ByVal pnPAID As Integer = 0, Optional ByVal pnUserID As Integer =
0, Optional ByVal peView As Filtering = Filtering.All) As Integer
Dim lobjData As CBillingData
Dim lnReturn As Integer

lnReturn = 0
Try
clStartTick = Now.Ticks

lobjData =
CType(MHSBusinessTier.GetDataTierObject("CBillingData"), CBillingData)
lnReturn = ParseDetails(lobjData.GetBillingItemsDS(plBillID,
pnPAID, pnUserID, peView))
Catch ex As MHSData.UnhandledSQLException
MessageBox.Show(ex.Message, "SQL Error - Getting Billable
Items")
lnReturn = -1
Catch ex As MHSData.UnhandledException
MessageBox.Show(ex.Message, "Error Getting Billable Items")
lnReturn = -1
Catch ex As Exception
MessageBox.Show(ex.ToString, "General Error")
lnReturn = -1
Finally
If Not (lobjData Is Nothing) Then
lobjData.Close()
lobjData = Nothing
End If
End Try

Return lnReturn
End Function

Then it will use that object to send parameters to. Then on the Datatier
side it will use those parameters to get data from the database and return a
dataset. This routine passes back a dataset with no problem when the
dataset is small but when it is large, for the test I am doing it is about
50Megs of data, it then generate the error you see above.

Public Function GetBillingItemsDS(ByVal plBillID As Long, ByVal pnPAID
As Integer, ByVal pnUserID As Integer, ByVal piView As Short) As DataSet
Implements CBillingData.GetBillingItemsDS
' create a command...
Dim command As SqlCommand
Dim sqlParms As New SqlClient.SqlParameter
Dim adapter As SqlDataAdapter
Dim result As New DataSet

Try
If mobjConnection.State = ConnectionState.Closed Then
mobjConnection.Open()
End If
' create the command...
command = New SqlCommand("SP..Name..Here", mobjConnection)
command.CommandTimeout = TimeOutLength

' set it up as a sproc...
command.CommandType = CommandType.StoredProcedure

.... Parameters are passed to SP here ....

' execute it...
adapter = New SqlDataAdapter(command)
adapter.Fill(result)
Catch ex As SqlException
WriteException("SQL Ex: " & ex.ToString)
Throw New UnhandledSQLException(ex)
Catch ex As Exception
WriteException("General Ex: " & ex.ToString)
Throw New UnhandledException(ex)
Finally
' dispose...
If Not adapter Is Nothing Then
adapter.Dispose()
End If
If Not command Is Nothing Then
command.Dispose()
End If
End Try

WriteException("Return: " & result.Tables.Count)

Try
' return...
Return result
Catch ex As Exception
WriteException("General Ex: " & ex.ToString)
End Try
End Function

The error seems to be happening after the return has run and the function
has exit. I think it has to do with the serialization of the dataset.
Maybe it is taking to long.

Now the machines I have tried this on have LOTS of memory from 512 - 2 GIG
and the code still fails. I have set and watched the processes.

As for memory use, the client which is hung is not peaked out of memory, it
is running 1% cpu usage and barely any memory used. The client program is
holding steady at 15Meg of memory usage. On the server the server is
holding at 98Meg of memory usage, 1% of CPU usage, and does not even look
like there is a process running.

So if anyone have any ideas please let me know, post some code, what should
I do, HELP!

Thanks

Clyde

Re: Error Using Remoting, System.OutOfMemoryException anyone ever seen this? Beth Massi [Architect MVP]
7/4/2005 1:22:52 PM
If serialization is your problem (and a 50 meg dataset is rather large) you
should serialize the dataset as binary. You can do this in v 2.0 of the .NET
framework by setting the Dataset.RemotingFormat property equal to
SerializationFormat.Binary. If you are using 1.1 of the .NET framework you
will need to use a surrogate class. Take a look here for a link to the code:
http://bethmassi.blogspot.com/2004/12/binary-serialization-of-datasets.html

HTH,
-B

[quoted text, click to view]

Re: Error Using Remoting, System.OutOfMemoryException anyone ever seen this? Microsoft News
7/5/2005 7:29:04 PM
Beth

You are a life savior, that worked like a charm for me. I was able to use
it to transfer the DataSet to the client like I wanted.

Thank you so much for the help.

Clyde
[quoted text, click to view]
AddThis Social Bookmark Button