1

我正在开发一个使用 Minitab DCOM 对象的 ASP 网页。我的问题是,如果在组件服务 (DCONCNFG) 下将身份设置为“此用户”,但如果我使用在“此用户”下使用的用户登录 Windows 并将身份设置为“交互式用户”一切正常。

我的问题是,如果用户名相同(管理员),DCOM 身份“交互式用户”和“此用户”有什么不同?

主要是这个网页使用 Minitab 来生成图表。在挂起之前,它确实会生成图表,但只有 5 或 6 个图表,然后它会停止响应。

这是 C# 代码,如果您想知道它挂在哪里:

using System;
using System.Web;
using System.Web.UI.WebControls;
using Mtb;        // Minitab Library (Mtb 16.0 Type Library)
using System.IO;
using System.Data;
using System.Runtime.InteropServices;
using System.Threading;




namespace TRWebApp.TestDetails
{
    public partial class TestDetails : System.Web.UI.Page
    {

        // MiniTab Stuff
        Mtb.IApplication g_MtbApp;
        Mtb.IProject g_MtbProj;
        Mtb.IUserInterface g_MtbUI;
        Mtb.IWorksheets g_MtbWkShts;
        Mtb.ICommands g_MtbCommands;

        Mtb.IOutputs g_MtbOutputs;
        Mtb.IGraph g_MtbGraph;

        Mtb.IOutputs g_MtbOutputs2;
        Mtb.IGraph g_MtbGraph2;

        int g_GraphIdx = 1;

        int g_Loop = 1;

        // Tests Table
        enum testsTable { TestIdx, TestSeq, ParamName, LSL, USL, Units };

        Tools tools = new Tools();

        string g_SessionID = "";

        Mtb_DataSetTableAdapters.XBarTableAdapter xbarTA = new Mtb_DataSetTableAdapters.XBarTableAdapter();

        protected void Page_Init(object sender, EventArgs e) 
        {
            g_MtbApp = new Application();
            g_MtbProj = g_MtbApp.ActiveProject;
            g_MtbUI = g_MtbApp.UserInterface;
            g_MtbWkShts = g_MtbProj.Worksheets;
            g_MtbCommands = g_MtbProj.Commands;

            g_MtbUI.DisplayAlerts = false;
            g_MtbUI.Interactive = false;
            g_MtbUI.UserControl = false; 


            lblProductDesc.Text = "";       // Start with a clear variable

            g_SessionID = HttpContext.Current.Session.SessionID;


            string imgFolder = "Images/Mtb/";

            string mtbSessionPath = Server.MapPath(ResolveUrl("~/" + imgFolder)) + g_SessionID;

            Directory.CreateDirectory(mtbSessionPath);
            Array.ForEach(Directory.GetFiles(mtbSessionPath), File.Delete); // Delete all the files from the directory

            Session["MtbSessionPath"] = mtbSessionPath;   // Store the Session Path so we can later delete it


            // Add the two image columns to the grid view
            GridView1.AutoGenerateColumns = false;

            ImageField imgColumn = new ImageField();
            imgColumn.HeaderText = "Scatterplot";
            imgColumn.DataImageUrlField = "TestIdx";
            imgColumn.DataImageUrlFormatString = "~\\Images\\Mtb\\" + g_SessionID + "\\{0}.GIF";
            imgColumn.ControlStyle.CssClass = "MtbImgDetail";
            GridView1.Columns.Add(imgColumn);

            ImageField img2Column = new ImageField();
            img2Column.HeaderText = "Histogram";
            img2Column.DataImageUrlField = "TestIdx";
            img2Column.DataImageUrlFormatString = "~\\Images\\Mtb\\" + g_SessionID + "\\H{0}.GIF";
            img2Column.ControlStyle.CssClass = "MtbImgDetail";
            GridView1.Columns.Add(img2Column);


        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                lblErrMsg.Text = "";

                // Fill dates if they are empty
                if (String.IsNullOrEmpty(tbxFromDate.Text))
                    tbxFromDate.Text = String.Format("{0:MM/01/yy}", DateTime.Today, null, DateTime.Today);
                if (String.IsNullOrEmpty(tbxToDate.Text))
                    tbxToDate.Text = String.Format("{0:MM/dd/yy}", DateTime.Today);

            }
            catch (Exception ex)
            {
                lblErrMsg.Text = ex.Message;
            }           

        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex >= 0)
            {
                // Get the data for the parameter name
                DataTable dt = xbarTA.GetXBarData(lbxProduct.SelectedValue, Convert.ToDateTime(tbxFromDate.Text), Convert.ToDateTime(tbxToDate.Text), e.Row.Cells[(int)testsTable.ParamName].Text);

                // Pass the data to an object array so we can pass it to minitab
                object[] data = new object[dt.Rows.Count];
                object[] time = new object[dt.Rows.Count];

                int i = 0;
                foreach (DataRow dr in dt.Rows)
                {
                    if (tools.IsNumeric(dr["ParamValue"]))
                    {
                        data[i] = Convert.ToDouble(dr["ParamValue"]);
                        time[i] = i;
                    }
                    i++;
                }

                if (dt.Rows.Count > 1)  // Do graphs with at least two measurements
                {
                    // Only pass it to minitab if we have numeric data
                    if (!ReferenceEquals(data[0], null))        // if it is not null it means it has a numeric value
                    {
                        g_MtbWkShts.Item(1).Columns.Add().SetData(data);
                        g_MtbWkShts.Item(1).Columns.Add().SetData(time);

                        g_MtbWkShts.Item(1).Columns.Item(1).Name = e.Row.Cells[(int)testsTable.ParamName].Text + " (" + e.Row.Cells[(int)testsTable.Units].Text + ")";
                        g_MtbWkShts.Item(1).Columns.Item(2).Name = "Time";


                        ////  H  E  R  E
                        ////
                        //// FOLLOWING LINE HANGS AFTER GENERATING 6 GRAPHS WHEN THE IDENTITY "THIS USER" IS SET
                        ////
                        g_MtbProj.ExecuteCommand("Plot C1*C2;\nSymbol;\nConnect.", g_MtbWkShts.Item(1));

                        // Convert LSL and USL to Decimal
                        if (tools.IsNumeric(e.Row.Cells[(int)testsTable.LSL].Text.Trim()) && tools.IsNumeric(e.Row.Cells[(int)testsTable.USL].Text.Trim()))
                        {
                            if (Convert.ToDouble(e.Row.Cells[(int)testsTable.LSL].Text) < Convert.ToDouble(e.Row.Cells[(int)testsTable.USL].Text))
                            {
                                g_MtbProj.ExecuteCommand("Capa C1 " + dt.Rows.Count.ToString() + ";\nLspec " + e.Row.Cells[(int)testsTable.LSL].Text + ";\nUspec " + e.Row.Cells[(int)testsTable.USL].Text + ";\nPooled;\nAMR;\nUnBiased;\nOBiased;\nToler 6;\nWithin;\nOverall;\nCStat.", g_MtbWkShts.Item(1));
                            }
                            else
                            {
                                g_MtbProj.ExecuteCommand("Histogram C1;\nBar;\nDistribution;\nNormal.", g_MtbWkShts.Item(1));
                            }
                        }
                        else
                        {
                            g_MtbProj.ExecuteCommand("Histogram C1;\nBar;\nDistribution;\nNormal.", g_MtbWkShts.Item(1));
                        }

                        try
                        {
                            g_MtbOutputs = g_MtbCommands.Item(g_GraphIdx).Outputs;
                            g_GraphIdx++;
                            g_MtbOutputs2 = g_MtbCommands.Item(g_GraphIdx).Outputs;
                            g_GraphIdx++;

                            string graphPath = "";
                            if (g_MtbOutputs.Count > 0)
                            {
                                g_MtbGraph = g_MtbOutputs.Item(1).Graph;

                                graphPath = Server.MapPath(ResolveUrl("~/Images/Mtb/")) + g_SessionID + Path.DirectorySeparatorChar + e.Row.Cells[(int)testsTable.TestIdx].Text + ".gif";
                                g_MtbGraph.SaveAs(graphPath, true, MtbGraphFileTypes.GFGIF, 600, 400, 96);
                            }

                            if (g_MtbOutputs2.Count > 0)
                            {
                                g_MtbGraph2 = g_MtbOutputs2.Item(1).Graph;

                                graphPath = Server.MapPath(ResolveUrl("~/Images/Mtb/")) + g_SessionID + Path.DirectorySeparatorChar + "H" + e.Row.Cells[(int)testsTable.TestIdx].Text + ".gif";
                                g_MtbGraph2.SaveAs(graphPath, true, MtbGraphFileTypes.GFGIF, 600, 400, 96);
                            }                                
                        }
                        catch (Exception ex)
                        {
                            lblErrMsg.Text = "Test Idx: " + e.Row.Cells[(int)testsTable.TestIdx].Text + " seems to have problems.<BR />Error: " + ex.Message;
                        }

                        g_MtbWkShts.Item(1).Columns.Delete();  // Delete all the columns (This line of code is needed otherwise the Mtb.exe will still running on the server side task manager


                    }
                    else
                    {
                        // Copy the No numeric image as a graph
                        File.Copy(Server.MapPath("~\\Images\\Mtb\\NaN.gif"), Server.MapPath("~\\Images\\Mtb\\" + g_SessionID + "\\" + e.Row.Cells[(int)testsTable.TestIdx].Text + ".gif"));
                        File.Copy(Server.MapPath("~\\Images\\Mtb\\NaN.gif"), Server.MapPath("~\\Images\\Mtb\\" + g_SessionID + "\\H" + e.Row.Cells[(int)testsTable.TestIdx].Text + ".gif"));
                    }
                }
            }
        }

        protected void GridView1_Unload(object sender, EventArgs e)
        {
            // All these lines of code are needed otherwise the Mtb.exe will not be close on the task manager (server side)
            GC.Collect();
            GC.WaitForPendingFinalizers();

            if (g_MtbGraph != null)
                Marshal.ReleaseComObject(g_MtbGraph); g_MtbGraph = null;
            if (g_MtbOutputs != null)
                Marshal.ReleaseComObject(g_MtbOutputs); g_MtbOutputs = null;

            if (g_MtbGraph2 != null)
                Marshal.ReleaseComObject(g_MtbGraph2); g_MtbGraph2 = null;
            if (g_MtbOutputs2 != null)
                Marshal.ReleaseComObject(g_MtbOutputs2); g_MtbOutputs2 = null;

            if (g_MtbCommands != null)
                Marshal.ReleaseComObject(g_MtbCommands); g_MtbCommands = null;
            if (g_MtbWkShts != null)
                Marshal.ReleaseComObject(g_MtbWkShts); g_MtbWkShts = null;
            if (g_MtbUI != null)
                Marshal.ReleaseComObject(g_MtbUI); g_MtbUI = null;
            if (g_MtbProj != null)
                Marshal.ReleaseComObject(g_MtbProj); g_MtbProj = null;

            if (g_MtbApp != null)
            {
                g_MtbApp.Quit();
                Marshal.ReleaseComObject(g_MtbApp); g_MtbApp = null;
            }            
        }        
    }
}

我在用着:

Windows Server 2008 R2 标准版 (SP 1)

IIS 7.5.7600.16385

框架 4.0.30319

Visual Studio 2010 版本 10.0.30319.1

Minitab 16.1.0

谢谢你,巴勃罗

4

2 回答 2

1

只是一个猜测,基于多年前发生在我身上的事情:

出于某种原因,Minitab 正在显示某种模态错误对话框。当您将 DCOM 配置为作为某个用户(而不是交互式用户)启动时,该进程将获得自己的“windows station”,作为登录用户,您实际上看不到它。因此,在某个看不见的地方弹出了一个对话框,永远等待输入,因此挂起。 为什么显示对话框是另一回事,可能是权限问题。例如,有时,注册表的某些部分在不同的激活上下文中可用或不可用。

于 2013-09-27T17:39:06.703 回答
1

感谢 Jlew 的链接。它通过在此寄存器键上将寄存器值从“Shared Section=1024,20480,768”更改为“Shared Section= 1024,20480,2304 ”(大 3 倍)帮助我解决了这个问题:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems\Windows 这个值指定了一个内存堆用户未登录时的大小。我想处理所有 MiniTab 图表是不够的。

巴勃罗

于 2013-09-30T21:43:43.810 回答