Configuring SQL Memory Limits on Forefront TMG 2010
When Forefront TMG 2010 is installed, an instance of SQL Server 2008 Express is also installed to facilitate local firewall and web proxy logging. Some TMG administrators have reported that the SQL server process (sqlservr.exe) may consume an excessive amount of memory.

This occurs because SQL server performs its own internal memory management. By design it will consume large amounts of memory and hold it in reserve, which may appear to be a memory leak. However, if you observe the memory consumed by SQL server over an extended period of time, you will notice that it will periodically release memory as well.
In most cases, allowing SQL to handle the job of managing its memory without restriction poses no real problem. However, if your system is exhibiting signs of high memory pressure and you are confident that there are no other processes that are consuming excessive amounts of memory, you can configure SQL to limit the amount of memory that it will reserve. Before manually configuring SQL memory limits, review this blog post for a list of recommended settings.
Next, open an elevated command prompt and enter the following command:
osql –E –S .\msfw
After connecting to the SQL instance, enter the following commands:
USE master GO EXEC sp_configure 'show advanced options', 1 RECONFIGURE WITH OVERRIDE GO EXEC sp_configure 'max server memory (MB)', 1024 --configure 1GB limit, adjust as needed GO EXEC sp_configure 'show advanced options', 0 RECONFIGURE WITH OVERRIDE GO
This script assumes that you’ve chosen a 1GB (1024MB) memory limit. You can adjust the script above to reflect the values for your environment as required. Once complete, restart the SQL server service for the changes to take effect.
To view the currently configured memory limit, simply omit the numeric value after max server memory (MB), as shown here:
EXEC sp_configure 'max server memory (MB)'
To make things easier you can download these as script files and execute them using the following command:
osql –E –S .\msfw -i <path to script file>
You can find script files to show and set SQL memory limits here:





Good tips. Most notice this when they move a SQL server to a virtualized environment. Memory allocated was perfectly calculated and right sized for the VM, then SQL sucks it all up like a vacuum. Linux also does this for file system operations as well, but that is a whole other topic.
Great SQL statements provided though. Thanks for sharing
Tnx for this, I’ve been looking for this.
Dear Richard,
Thank you for the post.
Unfortunately, I am not able to open a connection to SQL Express instance, however Name Pipe is enabled.
Please find below for more information:
C:\Users\LAB>OSQL -E -S ./MSFW
[SQL Server Native Client 10.0]Named Pipes Provider: Could not open a
connection to SQL Server [3].
[SQL Server Native Client 10.0]Login timeout expired
[SQL Server Native Client 10.0]A network-related or instance-specific error
has occurred while establishing a connection to SQL Server. Server is not
found or not accessible. Check if instance name is correct and if SQL Server
is configured to allow remote connections. For more information see SQL Server
Books Online.
Please advise.
Thank you and regards,
You are using the wrong slash. It should be .\msfw and not ./msfw.
Thank you Richard
It works great!
Regards,
Richard,
I’ve a client using UAG2010 who perceived he has a memory leak as well.
I assume the same SQL express instance is installed when UAG us used?
If so, would it be safe to use the SQL commands on a UAG installation (It’s also an NLB array
so I imagine you’d have to manually apply the script to each array member.)
Thanks in advance,
Colin
Hi Colin,
Absolutely. Forefront TMG 2010 is installed when UAG 2010 is installed, so this script will function in exactly the same way on a UAG server.