Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 31st, 2006, 12:26 AM
Authorized User
 
Join Date: Oct 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to fix this error massage for the EventLog??

There is the code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace SubmissionClearance
    {
        /// <summary>
        /// Summary description for WebForm1.
        /// </summary>
        public class SubForm : System.Web.UI.Page
        {
            protected System.Web.UI.HtmlControls.HtmlAnchor AgAcc;
            protected System.Web.UI.HtmlControls.HtmlAnchor SubClr;
            protected System.Web.UI.WebControls.DropDownList ddlInsured;
            protected System.Web.UI.WebControls.TextBox txtFirst;
            protected System.Web.UI.WebControls.TextBox txtLast;
            protected System.Web.UI.WebControls.RequiredFieldValidator rfvtxtFirst;
            protected System.Web.UI.WebControls.RegularExpressionValidat or revtxtDOB;
            protected System.Web.UI.WebControls.Label lblInsured;
            protected System.Web.UI.WebControls.Label lblFirst;
            protected System.Web.UI.WebControls.Label lblLast;
            protected System.Web.UI.WebControls.Label lblDOB;
            protected System.Web.UI.WebControls.RequiredFieldValidator rfvtxtLast;
            protected System.Web.UI.WebControls.RequiredFieldValidator rfvtxtDOB;
            protected System.Web.UI.WebControls.RangeValidator rvtxtDOB;
            protected System.Web.UI.WebControls.Label lblZip;
            protected System.Web.UI.WebControls.TextBox txtZip;
            protected System.Web.UI.WebControls.RequiredFieldValidator rfvtxtZip;
            protected System.Web.UI.WebControls.RegularExpressionValidat or revtxtZip;
            protected System.Web.UI.WebControls.Label lblYrCraft;
            protected System.Web.UI.WebControls.TextBox txtYrCraft;
            protected System.Web.UI.WebControls.Label lblYYYY;
            protected System.Web.UI.WebControls.RangeValidator rvtxtYrCraft;
            protected System.Web.UI.WebControls.RequiredFieldValidator rfvtxtYrCraft;
            protected System.Web.UI.WebControls.RegularExpressionValidat or revtxtYrCraft;
            protected System.Web.UI.WebControls.Label lblSSN;
            protected System.Web.UI.WebControls.TextBox txtSSN;
            protected System.Web.UI.WebControls.RegularExpressionValidat or revtxtSSN;
            protected System.Web.UI.WebControls.Label lblAgent;
            protected System.Web.UI.WebControls.TextBox txtAgent;
            protected System.Web.UI.WebControls.Label lblLast4;
            protected System.Web.UI.WebControls.RequiredFieldValidator rfvAgent;
            protected System.Web.UI.WebControls.Label lblNewPur;
            protected System.Web.UI.WebControls.DropDownList ddlNewPur;
            protected System.Web.UI.WebControls.TextBox txtDOB;
            protected System.Web.UI.WebControls.Button btnSubmit;
            protected System.Web.UI.WebControls.ValidationSummary vsMakeSub;
            protected System.Web.UI.WebControls.Label lblStatus;
            protected System.Web.UI.WebControls.TextBox txtStatus;

            private string sSqlCmd;
            private string sConn;
            System.Data.OleDb.OleDbConnection oleDBConn;
            System.Data.OleDb.OleDbCommand oleDBCmd;
            private string strAgentNumber;
            protected System.Web.UI.WebControls.Button btnReset;
            private HttpCookie cookie;
            // private System.Data.OleDb.OleDbDataReader oleDBReader;


            private void Page_Load(object sender, System.EventArgs e)
            {
                // Put user code to initialize the page here

                rvtxtYrCraft.MaximumValue = DateTime.Today.Year.ToString();
                rvtxtYrCraft.MaximumValue = ((int)((DateTime.Today.Year) + 1)).ToString();

                OnInsuredSelect();
                if (!CookieTest())
                {
                    return;
                }
                strAgentNumber = cookie.Values["GeneralAgentNumber"];
            }

            private bool CookieTest()
            {
                cookie = Request.Cookies["MarkelMarine"];
                if (cookie == null)
                {
                    // Server.Transfer("../Agents/FormsLogin.aspx");
                    AgAcc.HRef = "../Agents/FormsLogin.aspx";
                    Response.Redirect(AgAcc.HRef,true);
                    return false;
                }
                return true;
            }

            private void OnInsuredSelect()
            {
                if (ddlInsured.SelectedValue == "Y")
                {
                    txtFirst.Enabled = false;
                    txtLast.Enabled = false;
                    txtDOB.Enabled = false;
                    txtZip.Enabled = false;
                    txtSSN.Enabled = false;
                    txtYrCraft.Enabled = false;
                    txtAgent.Enabled = false;
                    ddlNewPur.Enabled = false;
                    btnSubmit.Enabled = false;
                    txtFirst.Text = string.Empty;
                    txtLast.Text = string.Empty;
                    txtDOB.Text = string.Empty;
                    txtZip.Text = string.Empty;
                    txtSSN.Text = "9999";
                    txtYrCraft.Text = string.Empty;
                    txtAgent.Text = string.Empty;
                }
                else
                {
                    txtFirst.Enabled = true;
                    txtLast.Enabled = true;
                    txtDOB.Enabled = true;
                    txtZip.Enabled = true;
                    txtSSN.Enabled = true;
                    txtYrCraft.Enabled = true;
                    txtAgent.Enabled = true;
                    ddlNewPur.Enabled = true;
                    btnSubmit.Enabled = true;

                }


            }

            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                //
                // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                //
                InitializeComponent();
                base.OnInit(e);
            }

            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.ddlInsured.SelectedIndexChanged += new System.EventHandler(this.ddlInsured_SelectedIndexC hanged);
                this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
                this.btnReset.Click += new System.EventHandler(this.btnReset_Click);
                this.Load += new System.EventHandler(this.Page_Load);

            }
            #endregion

            private void ddlInsured_SelectedIndexChanged(object sender, System.EventArgs e)
            {
                OnInsuredSelect();

            }


            private void WriteToEventLog(string strLogEntry, EventLogEntryType eType)
            {
                string strSource = "MarkelMarine"; //name of the source
                string strLogType = "Application"; //type of the log
                string strMachine = "."; //machine name

                //if (!EventLog.SourceExists(strSource, strMachine))
                //{
                // EventLog.CreateEventSource(strSource, strLogType, strMachine);
                //}

                EventLog eLog = new EventLog(strLogType, strMachine, strSource);
                eLog.WriteEntry(strLogEntry, eType, 01);
            }


            private void btnSubmit_Click(object sender, System.EventArgs e)
            {
                if (!CookieTest())
                {
                    return;
                }

                Page.Validate();
                for(int nCnt=0;nCnt < Page.Validators.Count; nCnt++)
                {
                    if (!(Page.Validators[nCnt].IsValid))
                    {
                        return ;
                    }
                }
                try
                {
                    string ssn= txtSSN.Text;
                    string zip= txtZip.Text;
                    string firstName= txtFirst.Text;
                    string lastName= txtLast.Text;
                    string dateOfBirth= txtDOB.Text;
                    string craftYear= txtYrCraft.Text;
                    string sStatus= "Y";

                    firstName= Globals.GetSafeSqlString(firstName);
                    lastName= Globals.GetSafeSqlString(lastName);

                    txtStatus.Visible = false;

                    if (ssn == string.Empty)
                    {
                        txtSSN.Text = "9999";
                        ssn="9999";
                    }

                    sConn = System.Configuration.ConfigurationSettings.AppSett ings["MyConnection"];
                    using(oleDBConn = new OleDbConnection(sConn))
                    {
                        oleDBConn.Open();

                        txtStatus.Text = "Accepted";

                        // New submission logic per Marine dept:
                        // 1) (First or last name) and date of birth and boat year
                        // -or-
                        // 2) Last name and (zipcode or ssn) and boat year
                        // Exact match on names.

                        StringBuilder sql=new StringBuilder();
                        sql.Append ("SELECT distinct Agent FROM SubmissionDetails ");
                        sql.AppendFormat("WHERE (((TRIM(FirstName)='{0}' or TRIM(LastName)= '{1}') and DateOfBirth =#{2}#) ",firstName,lastName,dateOfBirth);
                        sql.AppendFormat("or (TRIM(LastName)= '{0}' and (ZipCode={1} or SSN={2}))) ",lastName,zip,ssn);
                        sql.AppendFormat("and YearOfCraft ={0} and Status = 'Y' and ExpiryDate >= Date()",craftYear);

                        //oleDBCmd = new OleDbCommand(sql.ToString(),oleDBConn);

                        object result=oleDBCmd.ExecuteScalar();

                        if(result!=null)
                        {
                            //found a match
                            txtStatus.Text ="Already Reserved";
                            sStatus= "N";
                            if(strAgentNumber==result.ToString())
                            {
                                //current agent submitted a dup
                                txtStatus.Text ="Duplicate Entry";
                                return;
                            }
                        }

                        //end new submission logic

                        //log the submission requests
                        sSqlCmd = "INSERT INTO [SubmissionDetails](FirstName,LastName,DateOfBirth,SSN,ZipCode," +
                            "YearOfCraft,NewPurchase,Agent,AgentInitial,Create By,UpdateBy,Status) " +
                            "Values('" + firstName + "','" + lastName + "','" + dateOfBirth + "'" +
                            "," + ssn + "," + zip + "," + craftYear + ",'" + ddlNewPur.SelectedValue + "','" + strAgentNumber + "','" + txtAgent.Text + "'" +
                            ",'" + strAgentNumber + "','" + strAgentNumber + "','" + sStatus + "')";

                        oleDBCmd = new OleDbCommand(sSqlCmd,oleDBConn);
                        oleDBCmd.ExecuteNonQuery();
                        oleDBConn.Close();
                    }
                }
                catch (Exception e1)
                {
                    txtStatus.Text = e1.ToString();//"An error occurred during submission.";
                    WriteToEventLog(e1.Message, EventLogEntryType.Error);
                }
                finally
                {
                    txtStatus.Visible = true;
                }

            }

            private void btnReset_Click(object sender, System.EventArgs e)
            {
                txtFirst.Text = string.Empty;
                txtLast.Text = string.Empty;
                txtDOB.Text = string.Empty;
                txtZip.Text = string.Empty;
                txtSSN.Text = "9999";
                txtYrCraft.Text = string.Empty;
                txtAgent.Text = string.Empty;
                txtStatus.Text = string.Empty;

            }


        }
I have written the code (underline) for the Exception (e1) to write to the EventLog (application) if there is an error message to display. But when I go to the eventlog to see the error and get “The description for Event ID ( 1 ) in Source ( MarkelMarine ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: Object reference not set to an instance of an object..”
Here is the file Dll:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servic es\Eventlog\Application\MarkelMarine]
"EventMessageFile"="C:\\WINNT\\Microsoft.NET\\Fram ework\\v1.1.4322\\EventLogMessages.dll"

I am not sure how to fix this error massage for the EventLog. Let me know if there are any questions?? So if someone could help me with this please…thanks!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Fix Error sgafar ASP.NET 1.0 and 1.1 Basics 0 May 30th, 2007 10:22 AM
EventLog error Bob Bedell ASP.NET 1.0 and 1.1 Professional 0 November 26th, 2006 09:59 PM
how to fix this Parser Error Message? method ASP.NET 1.0 and 1.1 Basics 0 May 25th, 2005 11:09 AM
Cannot figure out how to fix error in Tomcat 5 Bluelicious Apache Tomcat 1 December 4th, 2004 03:14 PM
Purge a certain massage in MSMQ scorpion VB How-To 0 September 9th, 2003 05:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.