Groups | Blog | Home
all groups > dotnet datatools > march 2005 >

dotnet datatools : SqlCommand Memory Problems



Steve Spears via .NET 247
3/15/2005 3:01:27 PM
Hello, I need some help finding out what I am missing here=2E I=
have a connection to a SQL server, which I hope I am closing=
correctly, leaking memory=2E The function is called from a Timer=
and it is leaking 4 to 8k per cycle=2E I thought it was the GC=
not cleaning up but after a 24 hour period the app was at 24MB=
of memory=2E=2E=2E

Sub ProcessHB(ByVal strServer As String, ByVal RobotNumber As=
Integer)
Try
Dim ComputerName As String
ComputerName =3D System=2ENet=2EDns=2EGetHostName

Dim con As New SqlConnection("Data Source=3D" &=
strServer & ";" & _
"Initial Catalog=3DMyDBName;Integrated=
Security=3DSSPI")
con=2EOpen()
Dim cmd As SqlCommand =3D New SqlCommand("INSERT SQL=
UPDATE STATEMENT", con)
cmd=2EExecuteNonQuery()
cmd=2EDispose()
cmd =3D Nothing
con=2EClose()
con=2EDispose()
con =3D Nothing
strServer =3D Nothing
RobotNumber =3D Nothing
GC=2ECollect()
Catch ex As System=2EInvalidOperationException
Console=2EWriteLine(ex=2EMessage)
Catch ex As System=2EData=2ESqlClient=2ESqlException
Console=2EWriteLine(ex=2EMessage)
End Try

End Sub


--------------------------------
From: Steve Spears

-----------------------
Posted by a user from =2ENET 247 (http://www=2Edotnet247=2Ecom/)

Philipp Schumann
3/29/2005 4:22:07 PM
Hi Steve,

GC only collects when it _needs_ to. Given todays RAM capacities, 24MB (I
assume this was the working set?) doesn't have to force a GC collection,
unless there are a lot of other memore-intensive applications yearning for
more.

"Steve Spears via .NET 247" <anonymous@dotnet247.com> schrieb im Newsbeitrag
news:%23aTOsLbKFHA.1176@TK2MSFTNGP15.phx.gbl...
Hello, I need some help finding out what I am missing here. I have a
connection to a SQL server, which I hope I am closing correctly, leaking
memory. The function is called from a Timer and it is leaking 4 to 8k per
cycle. I thought it was the GC not cleaning up but after a 24 hour period
the app was at 24MB of memory...

Sub ProcessHB(ByVal strServer As String, ByVal RobotNumber As Integer)
Try
Dim ComputerName As String
ComputerName = System.Net.Dns.GetHostName

Dim con As New SqlConnection("Data Source=" & strServer & ";" &
_
"Initial Catalog=MyDBName;Integrated Security=SSPI")
con.Open()
Dim cmd As SqlCommand = New SqlCommand("INSERT SQL UPDATE
STATEMENT", con)
cmd.ExecuteNonQuery()
cmd.Dispose()
cmd = Nothing
con.Close()
con.Dispose()
con = Nothing
strServer = Nothing
RobotNumber = Nothing
GC.Collect()
Catch ex As System.InvalidOperationException
Console.WriteLine(ex.Message)
Catch ex As System.Data.SqlClient.SqlException
Console.WriteLine(ex.Message)
End Try

End Sub


--------------------------------
From: Steve Spears

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>LEUI7WhXsUibbKLjJO+sJw==</Id>

AddThis Social Bookmark Button