编程回收池在同一池中asp.net应用程序 [英] programatically recycle pool from asp.net application in same pool

查看:85
本文介绍了编程回收池在同一池中asp.net应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个ASP.net web应用程序这几天工作正常,但然后随机把一些数据库连接字符串例外,因此0条记录在表中(应该表现出上百个)上市。我花了几个星期的调试,内存是好的,数据库存在,它是由做任何会导致应用程序回收固定。这需要等待,甚至重现了多日。

Have an ASP.net web app which works fine for a few days, but then randomly throws some database connection string exception and as a result 0 records are listed in a table (should show hundreds). I've spent many weeks debugging, memory is fine, the database exists and it's fixed by doing anything which would cause the application to recycle. It takes many days of waiting to even reproduce.

所以我在想,因为我知道不应该是0的记录,我怎么可以强制应用程序池中的Web应用程序回收(当我得到这个数据库异常或0的记录)。至少这样的网站将用户的下一个工作,我不必手动重新启动。

So I was thinking since I know there should never be 0 records, how can I force the application pool running the web app to recycle (when I get this database exception or 0 records). At least this way the web site will work for the next user and I don't have to manually restart it.

推荐答案

喜在这篇文章中,你可以找到相关的code重新开始从Asp.net应用程序池

Hi in this article you can find relevant code to restart application pool from Asp.net

<一个href=\"http://terrapinstation.word$p$pss.com/2008/06/12/restart-iis-application-pool-from-aspnet-page/\"相对=nofollow>从ASP.NET页面重新启动IIS应用程序池

Restart IIS application pool from ASP.NET page

using System;
using System.Web;
using System.Web.UI;
using System.Management;
using System.DirectoryServices;
using System.Web.UI.WebControls;

public partial class iis : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(System.Environment.MachineName);
        status();
    }

    protected void status()
    {
        string appPoolName = "dev.somesite.com";
        string appPoolPath = @"IIS://" + System.Environment.MachineName + "/W3SVC/AppPools/" + appPoolName;
        int intStatus = 0;
        try
        {
            DirectoryEntry w3svc = new DirectoryEntry(appPoolPath);
            intStatus = (int)w3svc.InvokeGet("AppPoolState");
            switch (intStatus)
            {
                case 2:
                    lblStatus.Text = "Running";
                    break;
                case 4:
                    lblStatus.Text = "Stopped";
                    break;
                default:
                    lblStatus.Text = "Unknown";
                    break;
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
    protected void stopAppPool(object sender, EventArgs e)
    {
        Button btn = (Button)sender;
        string appPoolName = btn.CommandArgument;
        string appPoolPath = @"IIS://" + System.Environment.MachineName + "/W3SVC/AppPools/" + appPoolName;
        try
        {
            DirectoryEntry w3svc = new DirectoryEntry(appPoolPath);
            w3svc.Invoke("Stop", null);
            status();
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }

    protected void startAppPool(object sender, EventArgs e)
    {
        Button btn = (Button)sender;
        string appPoolName = btn.CommandArgument;
        string appPoolPath = @"IIS://" + System.Environment.MachineName + "/W3SVC/AppPools/" + appPoolName;
        try
        {
            DirectoryEntry w3svc = new DirectoryEntry(appPoolPath);
            w3svc.Invoke("Start", null);
            status();
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
}

这篇关于编程回收池在同一池中asp.net应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆