Jakki

Jakki

  • NA
  • 5
  • 0

Insufficient memory to continue the execution of the program.

Sep 16 2009 11:40 AM
I am working on a web page that will display some server statistics on a remote server when requested.  I have this working for 3/4 servers that I am trying to display but the 4th server keeps getting an "Insufficient memory to continue the execution of the program." error as soon as the page starts to load.  The error is occurring at the scope.Connect() line of code. Here's the code:

public void GetDiskspace()
    {
        ConnectionOptions options = new ConnectionOptions();
        //options.Username = ServerName + "\\wwfadmin";
        options.Username = "server4\\id";
        options.Password = "password";       
        ManagementScope scope = new ManagementScope("\\\\server4\\root\\cimv2",options);
        scope.Connect(); // Error is occurring here

        // Check diskspace
        ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
        SelectQuery query1 = new SelectQuery("Select * from Win32_LogicalDisk");

        ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
        ManagementObjectCollection queryCollection = searcher.Get();
        ManagementObjectSearcher searcher1 = new ManagementObjectSearcher(scope, query1);
        ManagementObjectCollection queryCollection1 = searcher1.Get();

        // Create DataTable
        DataTable dsDataTable = new DataTable();
        DataColumn dsDataColumn;

        dsDataColumn = new DataColumn();
        dsDataColumn.DataType = Type.GetType("System.String");
        dsDataColumn.ColumnName = "Name";
        dsDataTable.Columns.Add(dsDataColumn);

        dsDataColumn = new DataColumn();
        dsDataColumn.DataType = Type.GetType("System.String");
        dsDataColumn.ColumnName = "Size";
        dsDataTable.Columns.Add(dsDataColumn);

        dsDataColumn = new DataColumn();
        dsDataColumn.DataType = Type.GetType("System.String");
        dsDataColumn.ColumnName = "FreeSpace";
        dsDataTable.Columns.Add(dsDataColumn);

        DataRow row;

        foreach (ManagementObject mo in queryCollection1)
        {
            // Display Logical Disks information
            row = dsDataTable.NewRow();
            row["Name"] = mo["Name"];
            decimal Size = Convert.ToDecimal(mo["Size"]) / 1073741824;
            string strSize = Size.ToString("N2");           
            row["Size"] = strSize;
            decimal FreeSpace = Convert.ToDecimal(mo["FreeSpace"]) / 1073741824;
            string strFreeSpace = FreeSpace.ToString("N2");
            row["FreeSpace"] = strFreeSpace;
            if (Size != 0)
            {
                dsDataTable.Rows.Add(row);
            }       
        }
        this.DiskSpaceGridView.DataSource = dsDataTable.DefaultView;
        this.DiskSpaceGridView.DataBind();
       
    }

I can't think of any reason this code would fail for this one server when it works for 3 other servers without a problem.  The error pops up immediately.  I thought it may be related to the connection, but was able to get into the server using Remote Desktop with the credentials I'm supplying without any issues. 

I'm at a complete loss as to how to solve this.  Can anyone see any reason why this wouldn't work for only one server?

Answers (4)