1. Este site usa cookies. Ao continuar a usar este site está a concordar com o nosso uso de cookies. Saber Mais.

Base de dados

Discussão em 'Web Development' iniciada por jillefski, 10 de Setembro de 2008. (Respostas: 6; Visualizações: 730)

  1. Boas,

    Estou a reformular um site que contém ficheiros em aspx para login, registo e alteração de dados. Optei por fazer uma parte do site em flash, e na outra parte mantive a estrutura anterior das páginas em aspx, alterando apenas a estética sem mexer na programação nem das aspx nem das aspx.cs, sendo a estrutura em html totalmente independente da que está em flash. A verdade é que, agora, mesmo que faça upload do site para o servidor (como estava antes de eu ter feito qualquer alteração, quando funcionava perfeitamente), tanto login como registo e alteração de dados deixaram de funcionar (aparece agora um erro Server Error in '/' Application.). O que vos peço, se for possivel, é que me ajudem a resolver esta situação ou a descobrir a base de dados (visto que no painel de controlo do alojamento não encontro nenhuma) para poder recuperar os registos. Espero ter sido claro em relação à situação, e deixo o meu email para eventuais esclarecimentos [email protected]. Aqui está o código da página "inscricaoutilizador.aspx.cs", desde já obrigado.

    Código:
    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 Microsoft.Data.Odbc;
     
    namespace stat
    {
    	/// <summary>
    	/// Summary description for inscricaoutilizador.
    	/// </summary>
    	public class inscricaoutilizador : System.Web.UI.Page
    	{
    		protected System.Web.UI.HtmlControls.HtmlInputText txt1;
    		protected System.Web.UI.HtmlControls.HtmlInputText txt2;
    		protected System.Web.UI.HtmlControls.HtmlInputText txt3;
    		protected System.Web.UI.HtmlControls.HtmlInputText txt4;
    		protected System.Web.UI.HtmlControls.HtmlInputText txt5;
    		protected System.Web.UI.HtmlControls.HtmlInputText txt6;
    		protected System.Web.UI.HtmlControls.HtmlInputText txt7;
    		protected System.Web.UI.HtmlControls.HtmlInputText txt8;
    		protected System.Web.UI.HtmlControls.HtmlInputText txt9;
    		protected System.Web.UI.HtmlControls.HtmlInputText txt10;
    		protected System.Web.UI.HtmlControls.HtmlInputText txt11;
    		protected System.Web.UI.HtmlControls.HtmlInputText txt14;
    		protected System.Web.UI.HtmlControls.HtmlInputText txt12;
    		protected System.Web.UI.HtmlControls.HtmlTable TABLE5;
    		protected System.Web.UI.HtmlControls.HtmlSelect txt15;
    		protected System.Web.UI.HtmlControls.HtmlSelect txt17;
    		protected System.Web.UI.HtmlControls.HtmlSelect txt18;
    		protected System.Web.UI.HtmlControls.HtmlSelect txt19;
    		protected System.Web.UI.HtmlControls.HtmlSelect txt20;
    		protected System.Web.UI.HtmlControls.HtmlSelect txt21;
    		protected System.Web.UI.HtmlControls.HtmlInputText txt16;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c1;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c2;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c3;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c4;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c5;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c6;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c7;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c8;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c9;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c10;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c11;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c12;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c13;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c14;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c15;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c16;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c17;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c34;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c33;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c32;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c31;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c30;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c29;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c28;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c27;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c26;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c25;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c24;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c23;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c18;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c19;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c20;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c21;
    		protected System.Web.UI.HtmlControls.HtmlInputCheckBox c22;
    		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator1;
    		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator3;
    		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator4;
    		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator5;
    		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator6;
    		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator7;
    		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator8;
    		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator9;
    		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
    		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2;
    		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator3;
    		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator10;
    		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator4;
    		protected System.Web.UI.WebControls.Label Label1;
    		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator224;
    		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator231;
    		protected System.Web.UI.WebControls.Button Button1;
    		protected System.Web.UI.HtmlControls.HtmlForm form1;
    		protected System.Web.UI.HtmlControls.HtmlInputText txt13;
    		protected String username = null;
    		protected System.Web.UI.WebControls.RegularExpressionValidator Regularexpressionvalidator5;
    		protected String password = null;
    	
    		private void Page_Load(object sender, System.EventArgs e)
    		{
    			if(Request.Params["alterar"] != null)
    				if(Session["username"] != null)
    				{
    					
    					/*MySqlConnection con = new MySqlConnection(
    						"User Id=root;Host=localhost;Database=stat;");*/
    					OdbcConnection con = new OdbcConnection(
    							"Driver={MySQL ODBC 3.51 Driver};SERVER=127.0.0.1;Database=stat;Uid=stat;password=stat;PORT=3306;");
    					con.Open();
    					OdbcCommand insbd = con.CreateCommand();
    					insbd.CommandText = "SELECT * FROM Utilizadores WHERE username='" 
    						+ Session["username"].ToString() + "'";
    					OdbcDataReader dr = insbd.ExecuteReader();
    
    					/*MySqlCommand insbd = con.CreateCommand();
    					insbd.CommandText = "SELECT * FROM Utilizadores WHERE username='" 
    						+ Session["username"].ToString() + "'";*/
    				
    					
    					//MySqlDataReader dr = insbd.ExecuteReader();
    					dr.Read();
    						
    						Label1.Text = "";										
    						username = Session["username"].ToString();
    						password = dr["password"].ToString();
    						txt1.Value = username;
    						txt2.Value = password;	txt3.Value = password;
    						txt4.Value = dr["nome"].ToString();	txt5.Value = dr["morada"].ToString();
    						txt6.Value = dr["codigopostal"].ToString();	txt7.Value = dr["localidade"].ToString();
    						txt8.Value = dr["concelho"].ToString();	txt9.Value = dr["telefone"].ToString();
    						txt10.Value = dr["fax"].ToString(); txt11.Value = dr["telemovel"].ToString();
    						txt12.Value = dr["email"].ToString(); txt13.Value = dr["dataNascimento"].ToString();
    						txt14.Value = dr["contribuinte"].ToString(); txt15.Value = dr["habilitacoes"].ToString();
    						txt16.Value = dr["profissao"].ToString(); txt17.Value = dr["estadocivil"].ToString();
    						txt18.Value = dr["tomouconhecimento"].ToString(); txt19.Value = dr["consultaemail"].ToString();
    						txt20.Value = dr["quantasvezes"].ToString(); txt21.Value = dr["horasinternet"].ToString();
    				//	}
    			
    					String inter = dr["interesses"].ToString();
    					c1.Checked = inter[0].ToString() == "1";  c2.Checked = inter[1].ToString() == "1";				
    					c3.Checked = inter[2].ToString() == "1"; c4.Checked = inter[3].ToString() == "1";
    					c5.Checked = inter[4].ToString() == "1"; c6.Checked = inter[5].ToString() == "1";
    					c7.Checked = inter[6].ToString() == "1"; c8.Checked = inter[7].ToString() == "1";
    					c9.Checked = inter[8].ToString() == "1"; c10.Checked = inter[9].ToString() == "1";
    					c11.Checked = inter[10].ToString() == "1"; c12.Checked = inter[11].ToString() == "1";
    					c13.Checked = inter[12].ToString() == "1"; c14.Checked = inter[13].ToString() == "1";
    					c15.Checked = inter[14].ToString() == "1"; c16.Checked = inter[15].ToString() == "1";
    					c17.Checked = inter[16].ToString() == "1"; c18.Checked = inter[17].ToString() == "1";
    					c19.Checked = inter[18].ToString() == "1"; c20.Checked = inter[19].ToString() == "1";
    					c21.Checked = inter[20].ToString() == "1"; c22.Checked = inter[21].ToString() == "1";
    					c23.Checked = inter[22].ToString() == "1"; c24.Checked = inter[23].ToString() == "1";
    					c25.Checked = inter[24].ToString() == "1"; c26.Checked = inter[25].ToString() == "1";
    					c27.Checked = inter[26].ToString() == "1"; c28.Checked = inter[27].ToString() == "1";
    					c29.Checked = inter[28].ToString() == "1"; c30.Checked = inter[29].ToString() == "1";
    					c31.Checked = inter[30].ToString() == "1"; c32.Checked = inter[31].ToString() == "1";
    					c33.Checked = inter[32].ToString() == "1"; c34.Checked = inter[33].ToString() == "1";
    					
    					txt1.Disabled = true;
    					txt2.Disabled = true;
    					txt3.Disabled = true;
    					Requiredfieldvalidator1.Enabled = false;
    					Requiredfieldvalidator231.Enabled = false;
    					dr.Close();
    					con.Close();					
    				}
    				else
    				{
    					Response.Redirect("login.aspx");
    				}	
    
    		}
    
    		#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.Button1.Click += new System.EventHandler(this.Button1_Click);
    			this.Load += new System.EventHandler(this.Page_Load);
    
    		}
    		#endregion
    
    
    	
    		private void Button1_Click(object sender, System.EventArgs e)
    		{
    			this.Validate();
    		
    			if(this.IsValid)
    			{
    			/*	MySqlConnection con = new MySqlConnection(
    					"User Id=root;Host=localhost;Database=stat;");
    			
    				MySqlCommand insbd = con.CreateCommand();
    				insbd.CommandText = "SELECT *  FROM Utilizadores WHERE username='" 
    					+ Request.Params["txt1"].ToString()+"'";
    				con.Open();
    				MySqlDataReader dr = insbd.ExecuteReader();*/
    				OdbcConnection con = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};SERVER=127.0.0.1;Database=stat;Uid=stat;password=stat;PORT=3306;");
    				con.Open();
    				username = (txt1.Disabled)?username:Request.Params["txt1"];
    				OdbcCommand insbd = con.CreateCommand();
    				insbd.CommandText = "SELECT * FROM Utilizadores WHERE username='" 
    									+ username +"'";
    				OdbcDataReader dr = insbd.ExecuteReader();
    				if(dr.Read() && !txt1.Disabled)
    				{
    					Label1.Text = "O utilizador já se encontra registado";
    					return;
    				}
    				if(Request.Params["txt2"] != Request.Params["txt3"] && !txt1.Disabled)
    				{
    					Label1.Text = "As passwords inseridas não coincidem";
    					return;
    				}
    				
    				dr.Close();				
    
    				if(txt1.Disabled)
    				{					
    					insbd.CommandText = "DELETE FROM Utilizadores WHERE username='" + username+"'";
    					insbd.ExecuteNonQuery();				
    					insbd.CommandText = "DELETE FROM creditos WHERE numeroquestionario=0 AND username='" +username + "'";
    					insbd.ExecuteNonQuery();
    				}
    
    				Label1.Text = "";
    				String interesses = "";
    				String par = "'" + ((txt1.Disabled)?username:Request.Params["txt1"]) + "','" 
    					+ ((txt1.Disabled)?password:Request.Params["txt2"]) + "','";
    				for(int i=1; i<=34 ; i++)
    					interesses += (Request.Params["c"+ i] == "1")?"1":"0";
    				interesses += "'";
    				for(int i = 4; i<=21 ;i++) 
    					par += Request.Params["txt"+i] + "','";
    				insbd.CommandText = "INSERT INTO Utilizadores VALUES(" +
    					par + interesses + ")";							
    				
    				insbd.ExecuteNonQuery();				
    				insbd.CommandText = "INSERT INTO creditos VALUES ('" + username + "',0,0)";
    				insbd.ExecuteNonQuery();
    				Label1.Text = "O utilizador foi registado com sucesso";
    				
    				
    				
    				con.Close();				
    				//	Button1.Visible = false;
    			}
    		}
    
    		
    
    	}
    }
     
  2. SoundSurfer

    SoundSurfer Power Member

    Vai ao event log do servidor, está lá o erro.
     
  3. Começo por agradecer a resposta.

    Como é que identifico o erro no event log?
     
  4. RicardoMoreira

    RicardoMoreira Power Member

    E o resto do erro? O problema pode nem estar no código...
     
  5. XiriX

    XiriX Banido

    Assim um palpite por alto, ou tens as App pool mal configuradas, ou o web.config está mas construido.
     
  6. Agradeço, desde já, a vossa ajuda. Aqui está o resto do erro.

    Server Error in '/' Application.

    Código:
    Runtime Error
    
    Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. 
    
    Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
    
    
    <!-- Web.Config Configuration File -->
    
    <configuration>
        <system.web>
            <customErrors mode="Off"/>
        </system.web>
    </configuration>
    
    Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
    
    
    <!-- Web.Config Configuration File -->
    
    <configuration>
        <system.web>
            <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
        </system.web>
    </configuration>
     
  7. RicardoMoreira

    RicardoMoreira Power Member

    Faz o que diz no erro para se poder ver o erro que está a dar correctamente, com debug também.
     

Partilhar esta Página