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

Posted on 2006-11-10
Last Modified: 2008-01-09
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?
Question by:IUFITS
LVL 10

Expert Comment

ID: 17915992
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 :(

Author Comment

ID: 17916443
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>")

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

                myCommand = Nothing
                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.

Author Comment

ID: 17916651
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

Author Comment

ID: 17916857
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?
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.


Expert Comment

ID: 17928752
.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.

Accepted Solution

prashantagarw10 earned 500 total points
ID: 17929755
I also got this prob. and i think i added something to connection string to fix this up.
I think it was something like connectiontimeout or simply timeout.

By the way why do u keep closing and opening connections everytime. Dont close a connection. Use persistant connection which u open at start of report. and close it at application end. and to address the problem in between by closing of conn. use a good try catch block and call ur sub to open a conn. in case its broken in between.


Assisted Solution

prashantagarw10 earned 500 total points
ID: 17929789
I think i got it. It was Connection Lifetime property. In ur case i wd. suggest to set it  to 10 in case you plan to close and open connections each time. But if you use a persistant connection dont add this to connection string.


Author Comment

ID: 17990746
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.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Flash ( has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now