Server Erorr

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • preeti13
    New Member
    • Aug 2007
    • 67

    #1

    Server Erorr

    Hi i have a code runing into my local computer when i uplode to the server it is giving me an error asking parameter @datecreated but i am not using in the @datecretaed parameter in that update store procedure please help me with this here is my code:
    Code:
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlTypes;
    using System.Data.SqlClient;
    using System.Text ;
    namespace Employee_Nomination
    {
    	/// <summary>
    	/// Summary description for Winner.
    	/// </summary>
    	public class Winner : System.Web.UI.Page
    	{
    		protected System.Web.UI.WebControls.DropDownList drpMonth;
    		protected System.Web.UI.WebControls.DataGrid gvEmployee;
    		protected System.Web.UI.WebControls.Label lblMassage;
    		protected System.Web.UI.WebControls.RequiredFieldValidator Month;
    		protected System.Web.UI.WebControls.DropDownList drpYear;
    		protected System.Web.UI.WebControls.Button cmdbutton;
    		protected System.Web.UI.WebControls.Label lblMassage1;
            
    
    		
    	
    		private void Page_Load(object sender, System.EventArgs e)
    		{
    
    			//Put user code to initialize the page here
    			if(this.IsPostBack==false)
    			{
    				this.DisplayData(); 
    			}
    			else 
    				this.DisplayChecked();
    				
    			string EomNomid;
    			EomNomid = Request.QueryString["EomNomid"];
    			if((EomNomid != string.Empty) && (EomNomid != null))
    			{
    				SqlConnection oConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]); 
    				SqlCommand objCmd = new SqlCommand("up_updatewinner",oConn);
    				objCmd.CommandType = CommandType.StoredProcedure;
    				objCmd.Parameters.Add(new SqlParameter("@EmployeeNominationID",EomNomid));
    				
    				oConn.Open();
    				objCmd.ExecuteNonQuery();
    				oConn.Close();         
    			
    				this.lblMassage1.Text="You have successfully edit this winner";
    			}
    
    
    	}
    
    		void DisplayData()
    	
    		{
    			
    		}
    
    		
    	
    
    		#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.drpMonth.SelectedIndexChanged += new System.EventHandler(this.drpMonth_SelectedIndexChanged);
    			this.drpYear.SelectedIndexChanged += new System.EventHandler(this.drpYear_SelectedIndexChanged);
    			this.cmdbutton.Click += new System.EventHandler(this.cmdbutton_Click);
    			this.Load += new System.EventHandler(this.Page_Load);
    			this.Load += new System.EventHandler(this.Page_Load);
    
    		}
    		#endregion
    		private void DisplayChecked()
    		{ 
    
    		}
    		private void cmdbutton_Click(object sender, System.EventArgs e)
    		{
    			
          
    			HtmlInputHidden objreason;
    			HtmlInputHidden objHidden; 
    			HtmlInputRadioButton rdoButton; 
    			DataGridItem item; 
    			for (int counter = 0; counter <= this.gvEmployee.Items.Count - 1; counter++) 
    			{ 
    				item = gvEmployee.Items[counter]; 
    				rdoButton = ((HtmlInputRadioButton)(item.FindControl("rdoEmployeeNominationID"))); 
    				objHidden = ((HtmlInputHidden)(item.FindControl("hidEmployeeNominationID"))); 
                 objreason=((HtmlInputHidden)(item.FindControl("hidreasonid")));
    				if (!(rdoButton == null & !(objHidden == null)&!(objreason==null))) 
    				{ 
    			 
    				
    					if (rdoButton.Checked == true) 
    					{ 
    						
    						string employee=objHidden.Value;
    
    						string reason=objreason.Value;
    
    
    		
    						SqlConnection oConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]); 
    			
    						SqlCommand objCmd = new SqlCommand("up_updateEmployeeNominations",oConn);
    						objCmd.CommandType = CommandType.StoredProcedure;
    						objCmd.Parameters.Add(new SqlParameter("@employeenominationid",employee));
    					    objCmd.Parameters.Add(new SqlParameter("@reasonid",reason));
    					 
    						oConn.Open();
    						objCmd.ExecuteNonQuery();
    						oConn.Close();
    
    
    					this.lblMassage.Text="This is Employee of the Month";
    					}
    
    		}
    				
    				
    	} 
    } 
    
    		
    	public void drpMonth_SelectedIndexChanged(object sender, System.EventArgs e)
    	{
    		SqlConnection oConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]);
    		SqlDataAdapter da = new SqlDataAdapter("usp_employeenominations",oConn);
    		DataSet ds = new DataSet();
    		da.SelectCommand.CommandType = CommandType.StoredProcedure;
    		
    		if (drpMonth.SelectedItem.Value.ToString ()!="")
    		{
    		da.SelectCommand.Parameters.Add(new SqlParameter("@Month",drpMonth.SelectedItem.Value));
    		}
    		if(drpYear.SelectedItem.Value.ToString ()!="")
    		{
    		da.SelectCommand.Parameters.Add(new SqlParameter("@Year", drpYear.SelectedItem.Value));
    		}
    	
    
    					oConn.Open();
    					da.SelectCommand.ExecuteNonQuery();
    					oConn.Close();
    		
    					da.Fill(ds);
    		
    		
    					this.gvEmployee.DataSource = ds;
    					this.DataBind();
    				
    				  
    					da.Dispose();
    
    			}
    
    		private void drpYear_SelectedIndexChanged(object sender, System.EventArgs e)
    		{
    			SqlConnection oConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]);
    			SqlDataAdapter da = new SqlDataAdapter("up_Nominations",oConn);
    			DataSet ds = new DataSet();
    			da.SelectCommand.CommandType = CommandType.StoredProcedure;
    		
    			if (drpYear.SelectedItem.Value.ToString () !="")
    			{
    				da.SelectCommand.Parameters.Add(new SqlParameter("@Year",drpYear.SelectedItem.Value));
    				
    			}
    			if (drpMonth.SelectedItem.Value.ToString ()!="")
    			{
    			   da.SelectCommand.Parameters.Add(new SqlParameter("@Month",drpMonth.SelectedItem.Value));
    				
    			}
    			
    
    			
    			
    
    		
    	}
    
    			}
    
    		}
    	
    And the store procedur is 
    
    [CODE]
    CREATE  PROCEDURE [dbo].[up_updateEmployeeNominations]
    (
     
     @EmployeeNominationID int,
    @reasonid int
    
    
    
    )
    as
    
    
    update  Reason  -- EmployeeNominations
    set    EmployeeSelected='1'
    from reason
    
     
    
    where
    reason.EmployeeNominationID=@EmployeeNominationID and reason.reasonid=@reasonid 
    GO

    [/CODE]
  • davef
    New Member
    • Sep 2007
    • 98

    #2
    Without going much through your code, if the server complains about a missing parameter in the update/insert statement, make sure you have default value set on the datecreated column in the database table. You can probably default it to getdate(). Otherwise, you have to supply it's value from the code.

    Comment

    • preeti13
      New Member
      • Aug 2007
      • 67

      #3
      Hi i don't need a @datecreated paramenter in there i am not using datecreated but i am getting the error like this
      @datecreated is not a parameter for procedure up_updateEmploy eeNominations.
      and store procedure is like this
      Code:
      CREATE PROCEDURE [dbo].[up_updateEmployeeNominations]
       
      @EmployeeNominationID int,
      @reasonid int
      
      as
      
      
      update  Reason  
      set    EmployeeSelected='1'
      where
      reason.EmployeeNominationID=@EmployeeNominationID and reason.reasonid=@reasonid 
      GO

      Comment

      • davef
        New Member
        • Sep 2007
        • 98

        #4
        Originally posted by preeti13
        Hi i don't need a @datecreated paramenter in there i am not using datecreated but i am getting the error like this
        @datecreated is not a parameter for procedure up_updateEmploy eeNominations.
        and store procedure is like this
        Code:
        CREATE PROCEDURE [dbo].[up_updateEmployeeNominations]
         
        @EmployeeNominationID int,
        @reasonid int
        
        as
        
        
        update  Reason  
        set    EmployeeSelected='1'
        where
        reason.EmployeeNominationID=@EmployeeNominationID and reason.reasonid=@reasonid 
        GO
        When you create a SqlDataAdapter, you supply a different name of sp:
        Code:
        SqlDataAdapter da = new SqlDataAdapter("up_Nominations",oConn);
        Check if that's not a problem.

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          I would suggest deleting the stored procedure and starting over with it.
          It kinda seems like the db enginge still thinks the stored procedure has that varriable in it.

          Comment

          • davef
            New Member
            • Sep 2007
            • 98

            #6
            Also, it helps to check the connection string just to make sure you're using the right database.

            Comment

            • preeti13
              New Member
              • Aug 2007
              • 67

              #7
              Hi all my problem is not solved yet i tried so hard but did not get the solution for this please help me my code is running fine to the local machin but when upload to the server it is giving me an error but i am not using that store procedur it is looking the old thing what should i do with this this is my code
              Code:
              using System;
              using System.Collections;
              using System.ComponentModel;
              using System.Data;
              using System.Drawing;
              using System.Web;
              using System.Web.SessionState;
              using System.Web.UI;
              using System.Web.UI.WebControls;
              using System.Web.UI.HtmlControls;
              using System.Data.SqlTypes;
              using System.Data.SqlClient;
              using System.Text ;
              namespace Employee_Nomination
              {
              	/// <summary>
              	/// Summary description for Winner.
              	/// </summary>
              	public class Winner : System.Web.UI.Page
              	{
              		protected System.Web.UI.WebControls.DropDownList drpMonth;
              		protected System.Web.UI.WebControls.DataGrid gvEmployee;
              		protected System.Web.UI.WebControls.Label lblMassage;
              		protected System.Web.UI.WebControls.RequiredFieldValidator Month;
              		protected System.Web.UI.WebControls.DropDownList drpYear;
              		protected System.Web.UI.WebControls.Button cmdbutton;
              		protected System.Web.UI.WebControls.Label lblMassage1;
                      
              
              		
              	
              		private void Page_Load(object sender, System.EventArgs e)
              		{
              
              			//Put user code to initialize the page here
              			if(this.IsPostBack==false)
              			{
              				this.DisplayData(); 
              			}
              			else 
              				this.DisplayChecked();
              				
              			string EomNomid;
              			EomNomid = Request.QueryString["EomNomid"];
              			if((EomNomid != string.Empty) && (EomNomid != null))
              			{
              				SqlConnection oConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]); 
              				SqlCommand objCmd = new SqlCommand("up_updatewinner",oConn);
              				objCmd.CommandType = CommandType.StoredProcedure;
              				objCmd.Parameters.Add(new SqlParameter("@EmployeeNominationID",EomNomid));
              				
              				oConn.Open();
              				objCmd.ExecuteNonQuery();
              				oConn.Close();         
              			
              				this.lblMassage1.Text="You have successfully edit this winner";
              			}
              
              
              	}
              
              		void DisplayData()
              	
              		{
              			
              		}
              
              		
              	
              
              		#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.drpMonth.SelectedIndexChanged += new System.EventHandler(this.drpMonth_SelectedIndexChanged);
              			this.drpYear.SelectedIndexChanged += new System.EventHandler(this.drpYear_SelectedIndexChanged);
              			this.cmdbutton.Click += new System.EventHandler(this.cmdbutton_Click);
              			this.Load += new System.EventHandler(this.Page_Load);
              			this.Load += new System.EventHandler(this.Page_Load);
              
              		}
              		#endregion
              		private void DisplayChecked()
              		{ 
              
              		}
              		private void cmdbutton_Click(object sender, System.EventArgs e)
              		{
              			
                    
              			HtmlInputHidden objreason;
              			HtmlInputHidden objHidden; 
              			HtmlInputRadioButton rdoButton; 
              			DataGridItem item; 
              			for (int counter = 0; counter <= this.gvEmployee.Items.Count - 1; counter++) 
              			{ 
              				item = gvEmployee.Items[counter]; 
              				rdoButton = ((HtmlInputRadioButton)(item.FindControl("rdoEmployeeNominationID"))); 
              				objHidden = ((HtmlInputHidden)(item.FindControl("hidEmployeeNominationID"))); 
                         objreason=((HtmlInputHidden)(item.FindControl("hidreasonid")));
              				if (!(rdoButton == null & !(objHidden == null)&!(objreason==null))) 
              				{ 
              			 
              				
              					if (rdoButton.Checked == true) 
              					{ 
              						
              						string employee=objHidden.Value;
              
              						string reason=objreason.Value;
              
              
              		
              						SqlConnection oConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]); 
              			
                                          SqlDataAdapter da = new SqlDataAdapter("dbo.up_updateemployee",oConn);
                                          da.SelectCommand.CommandType = CommandType.StoredProcedure;
                               da.SelectCommand.Parameters.Add(new SqlParameter("@employeenominationid",employee));
              						da.SelectCommand.Parameters.Add(new SqlParameter("@reasonid",reason));
              
              						oConn.Open();
              						da.SelectCommand.ExecuteNonQuery();
              						oConn.Close();
              
              					this.lblMassage.Text="This is Employee of the Month";
              					}
              
              		}
              				
              				
              	} 
              } 
              
              		
              	public void drpMonth_SelectedIndexChanged(object sender, System.EventArgs e)
              	{
              		SqlConnection oConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]);
              		SqlDataAdapter da = new SqlDataAdapter("usp_employeenominations",oConn);
              		DataSet ds = new DataSet();
              		da.SelectCommand.CommandType = CommandType.StoredProcedure;
              		
              		if (drpMonth.SelectedItem.Value.ToString ()!="")
              		{
              		da.SelectCommand.Parameters.Add(new SqlParameter("@Month",drpMonth.SelectedItem.Value));
              		}
              		if(drpYear.SelectedItem.Value.ToString ()!="")
              		{
              		da.SelectCommand.Parameters.Add(new SqlParameter("@Year", drpYear.SelectedItem.Value));
              		}
              	
              
              					oConn.Open();
              					da.SelectCommand.ExecuteNonQuery();
              					oConn.Close();
              		
              					da.Fill(ds);
              		
              		
              					this.gvEmployee.DataSource = ds;
              					this.DataBind();
              				
              				  
              					da.Dispose();
              
              			}
              
              		private void drpYear_SelectedIndexChanged(object sender, System.EventArgs e)
              		{
              			SqlConnection oConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]);
              			SqlDataAdapter da = new SqlDataAdapter("up_Nominations",oConn);
              			DataSet ds = new DataSet();
              			da.SelectCommand.CommandType = CommandType.StoredProcedure;
              		
              			if (drpYear.SelectedItem.Value.ToString () !="")
              			{
              				da.SelectCommand.Parameters.Add(new SqlParameter("@Year",drpYear.SelectedItem.Value));
              				
              			}
              			if (drpMonth.SelectedItem.Value.ToString ()!="")
              			{
              			   da.SelectCommand.Parameters.Add(new SqlParameter("@Month",drpMonth.SelectedItem.Value));
              				
              			}
              			
              
              			
              			
              
              		
              	}
              
              			}
              
              		}
              and here is the store procedure
              Code:
              CREATE PROCEDURE [dbo].[up_updateemployee] 
              
              @EmployeeNominationID int,
              @reasonid int
              
              as
              
              
              update  Reason  
              set    EmployeeSelected='1'
              where
              reason.EmployeeNominationID=@EmployeeNominationID and reason.reasonid=@reasonid
              
              
              GO
              And i am getting this error massage:

              @datecreated is not a parameter for procedure up_updateEmploy eeNominations.
              Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

              Exception Details: System.Data.Sql Client.SqlExcep tion: @datecreated is not a parameter for procedure up_updateEmploy eeNominations.

              Source Error:

              An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

              Stack Trace:


              [SqlException: @datecreated is not a parameter for procedure up_updateEmploy eeNominations.]
              System.Data.Sql Client.SqlComma nd.ExecuteReade r(CommandBehavi or cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +742
              System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery() +196
              Employee_Nomina tion.Winner.cmd button_Click(Ob ject sender, EventArgs e) in c:\inetpub\wwwr oot\employee nomination\winn er.aspx.cs:156
              System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
              System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
              System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
              System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
              System.Web.UI.P age.ProcessRequ estMain() +1292

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                And you are sure the connection string isn't like "localhost" or anything like that?

                Comment

                • davef
                  New Member
                  • Sep 2007
                  • 98

                  #9
                  How come in your
                  Code:
                  private void cmdbutton_Click(object sender, System.EventArgs e)
                  method you use SelectCommand property on the SqlDataAdapter object instead of UpdateCommand? All you're doing is update, right? You don't expect any dataset in return. Try to replace it.

                  Comment

                  • preeti13
                    New Member
                    • Aug 2007
                    • 67

                    #10
                    Hello sir
                    ye si am sure i am not using the local host connection in there i just put th config file mode "Off" instead of the"RmoteOnly" because with the remote only i can not see the exact error please help me with the i took almost 3 week s to fix that error but i could not find exactlly what is going on please help me

                    Comment

                    • preeti13
                      New Member
                      • Aug 2007
                      • 67

                      #11
                      Hi changed the code no wi am using objcommand instead of data adapter it is like this
                      Code:
                      private void cmdbutton_Click(object sender, System.EventArgs e)
                      		{
                      			
                            
                      			HtmlInputHidden objreason;
                      			HtmlInputHidden objHidden; 
                      			HtmlInputRadioButton rdoButton; 
                      			DataGridItem item; 
                      			for (int counter = 0; counter <= this.gvEmployee.Items.Count - 1; counter++) 
                      			{ 
                      				item = gvEmployee.Items[counter]; 
                      				rdoButton = ((HtmlInputRadioButton)(item.FindControl("rdoEmployeeNominationID"))); 
                      				objHidden = ((HtmlInputHidden)(item.FindControl("hidEmployeeNominationID"))); 
                                 objreason=((HtmlInputHidden)(item.FindControl("hidreasonid")));
                      				if (!(rdoButton == null & !(objHidden == null)&!(objreason==null))) 
                      				{ 
                      			 
                      				
                      					if (rdoButton.Checked == true) 
                      					{ 
                      						
                      						string employee=objHidden.Value;
                      
                      						string reason=objreason.Value;
                      
                      
                      		
                      						SqlConnection oConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]); 
                      			
                      						SqlCommand objCmd = new SqlCommand("dbo.up_updateemployee",oConn);
                      						objCmd.CommandType = CommandType.StoredProcedure;
                      						objCmd.Parameters.Add(new SqlParameter("@employeenominationid",employee));
                      					    objCmd.Parameters.Add(new SqlParameter("@reasonid",reason));
                      
                      		 
                      						oConn.Open();
                      						objCmd.ExecuteNonQuery();
                      						oConn.Close();

                      Comment

                      • davef
                        New Member
                        • Sep 2007
                        • 98

                        #12
                        Originally posted by preeti13
                        Hi changed the code no wi am using objcommand instead of data adapter it is like this
                        Code:
                        private void cmdbutton_Click(object sender, System.EventArgs e)
                        		{
                        			
                              
                        			HtmlInputHidden objreason;
                        			HtmlInputHidden objHidden; 
                        			HtmlInputRadioButton rdoButton; 
                        			DataGridItem item; 
                        			for (int counter = 0; counter <= this.gvEmployee.Items.Count - 1; counter++) 
                        			{ 
                        				item = gvEmployee.Items[counter]; 
                        				rdoButton = ((HtmlInputRadioButton)(item.FindControl("rdoEmployeeNominationID"))); 
                        				objHidden = ((HtmlInputHidden)(item.FindControl("hidEmployeeNominationID"))); 
                                   objreason=((HtmlInputHidden)(item.FindControl("hidreasonid")));
                        				if (!(rdoButton == null & !(objHidden == null)&!(objreason==null))) 
                        				{ 
                        			 
                        				
                        					if (rdoButton.Checked == true) 
                        					{ 
                        						
                        						string employee=objHidden.Value;
                        
                        						string reason=objreason.Value;
                        
                        
                        		
                        						SqlConnection oConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]); 
                        			
                        						SqlCommand objCmd = new SqlCommand("dbo.up_updateemployee",oConn);
                        						objCmd.CommandType = CommandType.StoredProcedure;
                        						objCmd.Parameters.Add(new SqlParameter("@employeenominationid",employee));
                        					    objCmd.Parameters.Add(new SqlParameter("@reasonid",reason));
                        
                        		 
                        						oConn.Open();
                        						objCmd.ExecuteNonQuery();
                        						oConn.Close();
                        If still no luck, open up the SQL Server Profiler on the server and start a new trace session to finally get the real picture. I hope you know how to do that. If not, let me know, I'll post some guidelines.

                        Comment

                        • preeti13
                          New Member
                          • Aug 2007
                          • 67

                          #13
                          Hi thanks for the suggation.but i ma not that much experinced so can you please tell me how to open up the SQL Server Profiler on the server

                          Comment

                          • davef
                            New Member
                            • Sep 2007
                            • 98

                            #14
                            Originally posted by preeti13
                            Hi thanks for the suggation.but i ma not that much experinced so can you please tell me how to open up the SQL Server Profiler on the server
                            Are you using 2000 or 2005? In 2005 Management Studio, go to Tools>SQL Server Profiler. Then, File>New Trace. Connect to the right SQL Server (according to your app conn string) and click Run. You'll be presented with a window having a grid of events. Look for TextData column. Start your app and click on the html button that allegedely produces an error. Go back to the Profiler and stop or pause the session. Go File>Export>Ext ract SQL Server Events and save it as .sql file. Open it and look for the name of your update stored procedure. It should be there along with the passed parameters if everything went right. If not, the fun will begin thereafter.

                            Comment

                            • preeti13
                              New Member
                              • Aug 2007
                              • 67

                              #15
                              Thanks very much i will let you know if i solve my problem with this

                              Comment

                              Working...