Jump to content

Recommended Posts

Posted

Olá,

Tenho um site alojado na esoterica com bd mysql.

Já Criei a bd na esoterica.

O problema é o seguinte: faço a configuração no codigo mas não consigo conectar com a bd.

Alguem que já tenha usado me possa ajudar.

Posted

o meu codigo está assim:

String SERVIDOR = "localhost";
	 String BANCO = "ogomgma14856com15551_xxxx";
	 String USUARIO = "ogomg_xxxx";
	 String SENHA = "xxxxx";

	 MySqlConnection conDatabase = new MySqlConnection("Database=" + BANCO + ";Data Source=" + SERVIDOR + ";User Id=" + USUARIO + ";Password=" + SENHA + "; pooling=false");
Posted (edited)

esse código não diz nada ... que Framework é essa ?

4 queria mostrar a configuraçao no codigo para ver está correcto

Edited by diogom
Posted

o que queres dizer é que fizeste em .Net

nesse caso terás de esperar por alguem que use isso para te ajudar porque deverias ter aberto o tópico na secção de C#

Pensei que fosse aqui. Como o problema é com a bd.

Mas podes ajudar-me. No pc funciona tudo bem, mas desde que passei para a esoterica, não consgo por a funcionar.

Posted

Pensei que fosse aqui. Como o problema é com a bd.

Mas podes ajudar-me. No pc funciona tudo bem, mas desde que passei para a esoterica, não consgo por a funcionar.

Agora da-me este erro: 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.

Posted

Ali no exemplo lá em cima, estás a definir a ligação.

Depois tens de abrir com o conDatabase.Open();

Em relação a esse erro, dá em que linha?

Sim. Eu faço isso tudo.

public void Validar()
 {
	 String SERVIDOR = "localhost";
	 String BANCO = "ogomgma14856com15551_xxxx";
	 String USUARIO = "ogomg_xxxx";
	 String SENHA = "xxxx";
	 //string selectString = "SELECT user, pass " + "FROM fichadel " + "WHERE user = '" + userTB.Text + "' AND pass = '" + passTB.Text + "'";
	 MySqlConnection conDatabase = new MySqlConnection("Database=" + BANCO + ";Data Source=" + SERVIDOR + ";User Id=" + USUARIO + ";Password=" + SENHA + "; pooling=false");
	 conDatabase.Open();
	 MySqlDataReader leitura;
	 MySqlCommand command = conDatabase.CreateCommand();
	 command.CommandText = "SELECT user, pass, permissao " + "FROM fichadel " + "WHERE user = '" + userTB.Text + "' AND pass = '" + passTB.Text + "'"; //select de //demostração, metes o teu select

	 leitura = command.ExecuteReader();
	 if (leitura.Read())
	 {
		 string permissoes = leitura.GetString(2);
		 try
		 {
			 if (permissoes == "Admin")
			 {

				 Session["nome"] = userTB.Text;
				 Session.Timeout = 60;


				 Response.Redirect("admin.aspx?User=" + userTB.Text + "");
			 }
			 else if (permissoes == "Geral")
			 {

				 Session["nome"] = userTB.Text;
				 Session.Timeout = 60;


				 Response.Redirect("geral.aspx?User=" + userTB.Text + "");
			 }
			 else if (permissoes == "Basico")
			 {

				 Session["nome"] = userTB.Text;
				 Session.Timeout = 60;


				 Response.Redirect("area.aspx?User=" + userTB.Text + "");
			 }
		 }
		 catch (MySqlException msqle)
		 {
			 // MessageBox.Show("Erro de acesso ao MySQL: " + msqle.Message);
			 ClientScript.RegisterClientScriptBlock(this.GetType(), "MensagemDeAlert", "alert('Erro de acesso ao MySQL: " + msqle.Message + "');", true);
		 }
		 catch (Exception ex)
		 {
			 //MessageBox.Show("Erro inesperado: " + ex.Message);
			 ClientScript.RegisterClientScriptBlock(this.GetType(), "MensagemDeAlert", "alert('Erro inesperado: " + ex.Message + "');", true);
		 }
		 finally
		 {
			 if (conDatabase != null || conDatabase.State == System.Data.ConnectionState.Open)
				 conDatabase.Close();
			 leitura.Close();
		 }
	 }
	 else
	 {

		 string s = "alert('Utilizador ou senha errada!');var vers = navigator.appVersion;if(vers.indexOf('MSIE 7.0') != -1) { window.open('Default.aspx?erro=errologin&User=" + userTB.Text + "','_self');}";
		 ScriptManager.RegisterStartupScript(this, this.GetType(), "Information", s, true);

		 passTB.Text = "";
		 passTB.Focus();
	 }
Posted

Não dizes qual a linha que dá o erro

Quando carrego para validar, aparece uma pagina com isto:

Access denied for user 'root'@'localhost' (using password: YES)

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: MySql.Data.MySqlClient.MySqlException: Access denied for user 'root'@'localhost' (using password: YES)

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:

[MySqlException (0x80004005): Access denied for user 'root'@'localhost' (using password: YES)]

MySql.Data.MySqlClient.MySqlStream.ReadPacket() +276

MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket() +39

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.