All pastes #758077 Raw Edit

Something

public text v1 · immutable
·published 2007-11-01 21:37 UTC
rendered paste body
<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Text" %>
<%@ import Namespace="System.Diagnostics" %>
<%@ import Namespace="System.Web.Configuration" %>

<script language="C#" runat="server">
	/*
	 * $Id: testsetup.aspx 13 2007-05-01 21:51:03Z scott $
	 */
	
	public void Page_Load(Object src, EventArgs e)
	{

		bool BadConfig = false;
		if ((WebConfigurationManager.AppSettings["EventLogFile"] == null) || WebConfigurationManager.AppSettings["EventLogFile"].Equals(""))
		{
			Response.Write("Application setting \"EventLogFile\" missing in web.config\n");
			BadConfig = true;
		}

		if ((WebConfigurationManager.AppSettings["ConnectionString"] == null) || WebConfigurationManager.AppSettings["ConnectionString"].Equals(""))
		{
			Response.Write("Application setting \"ConnectionString\" missing in web.config\n");
			BadConfig = true;
		}

		if ((WebConfigurationManager.AppSettings["VerboseLogging"] == null) || WebConfigurationManager.AppSettings["VerboseLogging"].Equals(""))
		{
			Response.Write("Application setting \"VerboseLogging\" missing in web.config\n");
			BadConfig = true;
		}

		if ((!(WebConfigurationManager.AppSettings["VerboseLogging"] == null)) && (!(WebConfigurationManager.AppSettings["VerboseLogging"] == "Y") && !(WebConfigurationManager.AppSettings["VerboseLogging"] == "N")))
		{
			Response.Write("Invalid value for \"VerboseLogging\" in web.config\n");
			BadConfig = true;
		}		

		if (BadConfig) { return; }

		EventLog ev = new EventLog();
		
		try
		{

			ev.Log = WebConfigurationManager.AppSettings["EventLogFile"];
			ev.Source = "Configuration Analysis";
		}
		catch (Exception ex)
		{
			Response.Write("Error creating event log: " + ex.Message + "\n");
		}
		if (!EventLog.SourceExists(WebConfigurationManager.AppSettings["EventLogFile"]))
		{
			try
			{
				EventLog.CreateEventSource(ev.Source, WebConfigurationManager.AppSettings["EventLogFile"]);
			}
			catch (Exception ex)
			{
				Response.Write("Error creating event log: " + ex.Message + "\n");
				ev = null;
				return;
			}
		}

		try
		{
			ev.WriteEntry("Test Message");
		}
		catch (Exception ex)
		{
			Response.Write("Error writing to event log: " + ex.Message + "\n");
			ev = null;
			return;
		}

		ev = null;

		SqlConnection conn = new SqlConnection();
		try
		{
			conn.ConnectionString = WebConfigurationManager.AppSettings["ConnectionString"];
			conn.Open();
		}
		catch (Exception ex)
		{
			Response.Write("Error connecting to SQL Server: " + ex.Message + "\n");
			return;
		}
		finally
		{
			conn.Close();
		}

		conn = null;


		Response.Write("Test complete. If any errors were reported, correct the issue and re run this utility.\n");

	}
</script>

<html>
<head>
<title>
</title>
</head>
<body>
</body>
</html>