Link to home
Start Free TrialLog in
Avatar of IUFITS
IUFITS

asked on

"There are not enough free System Resources to perform this operation."

I get this error "There are not enough free System Resources to perform this operation." while running a report engine that I'm upgrading to use ADO.NET (worked fine with ADO).  It is essentially checking a Queue table every 3 seconds to see if a request has been made.  I'm using a SQL Data Reader, SQL Connection and SQL Command.

Here's the odd thing though, when the program throws the system resources error there are still plenty of system resources left.  The hard disk has 8 of 20 gig left.  The engines at crash time are taking up 54MB and 37MB of memory respectively and the commit charge via the task manager is only 287MB/1246MB.

I'm disposing of my SQLCommands and setting the commands and data reader = nothing.  The connection is left open throughout the lifetime of the .EXE.  Thoughts on why this is happening?
Avatar of Kinger247
Kinger247

This isn't an answer, but I've had this before and a reboot sorted it out.
Never found out what the problem was though :(
Avatar of IUFITS

ASKER

I'm puzzeled, the other kicker is, I have two database connections each database residing on a different server (one is our error and notification logging database).

                Dim Sqlstmt As String = "UPDATE tbl_Application_Codes SET ProgramLastRun='" & Now() & "', ProgramLastRunBy='" & My.User.Name & "', ProgramLastRunIP='" & GetIPAddress() & "' WHERE ApplicationCode='" & pAPPLICATION_CODE & "'"
                Dim myConnection As New System.Data.SqlClient.SqlConnection("server=<server>;database=Error_Log;uid=<user>;pwd=<Password>")
                myConnection.Open()

                Dim myCommand As New System.Data.SqlClient.SqlCommand(Sqlstmt, myConnection)
                Dim p As Integer = myCommand.ExecuteNonQuery()

                myCommand.Dispose()
                myCommand = Nothing
                myConnection.Close()
                myConnection = Nothing

I'm running the above code in the form load event of the main form.. it calls a sub in an custom notification object which contains the above... now, to me it looks like the connection should open, run the statement and close, but it doesn't and it doesn't throw an exception to make me think it's not getting there.  There continues to be two open connections to that database server and countless others with TIME_WAIT (I can only assume it opens then closes many over and over because the port number continues to go up when I check netstat)....   Clearly there is something I don't understand with the connection process.
Avatar of IUFITS

ASKER

I'm utterly perplexed.  Something else I noticed which is flakey, I removed SERVER1 from EVERY connection string in my source code a while back...  it's NOT there but my program continues to open up connections to it and close them (or I assume that because there's a slew of TIME_WAIT connections when my program starts).  Why does it continue to reference it... when I start my program and run netstat to monitor (I've used a packet sniffer which verifies my program is sending that server info).

How can my program be opening or talking to a server that exists nowhere in my code (though it used to) and could this somehow be related?  This makes me miss my trouble free version with classic ADO.  :P
Avatar of IUFITS

ASKER

Disregard the SERVER1 comment...  I forgot this is a report server and server1 was where the report was getting it's data from.  :P  This perplexed on the memory issue though.  Does it matter what order your dispose and set things equal to nothing in?
.NET will pool database connections, and keep them open for a while in case they are needed again.  That could explain why it looks like the connections aren't being closed.

I would call Dispose on the Connection object too, just be sure that it's not leaking anything.
ASKER CERTIFIED SOLUTION
Avatar of prashantagarw10
prashantagarw10

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of IUFITS

ASKER

I set a persistant connection and re-ordered the order I was releasing objects so I didnt' leave any hanging.  That helped.  My true leak though was from using NotifyIcon and not using the DestroyIcon API to free the resource since the icon setting was just a pointer.