2

I have the following connection string:

Data Source=localhost;UserID=root;Password=;Database=eyebus;

When I try to connect to the database I get an error saying that maybe the server was not found or not accessible. What is the problem with this string,?

I also tried other strings/words I found on the Internet, but none of them actually worked.

Also, the problem is not the server, since it can be accessed by other applications.

class SQLManager
    {

        private static string conString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ToString();


        public List<PesquisaOcorrenciasExistentesModel> getOcorrencias()
        {
            List<PesquisaOcorrenciasExistentesModel> ocorrencias = new List<PesquisaOcorrenciasExistentesModel>();

            using (SqlConnection con = new SqlConnection(conString))
            {
                try
                {
                    con.Open();
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
                using (SqlCommand com = new SqlCommand("SELECT * FROM ocorrencias", con))
                {
                    SqlDataReader reader = com.ExecuteReader();
                    while (reader.Read())
                    {
                        PesquisaOcorrenciasExistentesModel o = new PesquisaOcorrenciasExistentesModel();
                        o.IdOcorrencia = reader.GetInt16(0);
                        o.IdOcorrenciaTipo = reader.GetInt16(1);
                        o.DataInicio = reader.GetDateTime(2);
                        o.DataFim = reader.GetDateTime(3);
                        o.Operador = reader.GetString(4);
                        o.Motorista = reader.GetString(5);
                        o.Cobrador = reader.GetString(6);
                        o.Terceiros = reader.GetString(7);
                        o.Descricao = reader.GetString(8);
                        o.EmailsEnviados = reader.GetString(9);
                        o.TipoOcorrenciaOutro = reader.GetString(10);
                        ocorrencias.Add(o);
                    }
                }
            }

            return ocorrencias;
        }
    }
}
3
  • What database connection provider are you using? Commented Mar 1, 2013 at 19:15
  • Take a look at this post: stackoverflow.com/questions/10505952/… Commented Mar 1, 2013 at 19:15
  • MySql.Data.MySqlClient. I had already seen that post, but the presented solution didn't solve my problem. Commented Mar 1, 2013 at 19:16

1 Answer 1

2

Try using Server instead of Data Source, and UID instead of UserID.

Or check out this post, with more information: How to form a correct MySQL connection string?

Also, don't you need to use:

ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString

And, SqlConnection, SqlDataReader, and SqlCommand are used for Micrsoft SQL. I believe you should be using MySqlConnection, MySqlDataReader, and MySqlCommand.

Take a look at: http://www.codeproject.com/Articles/43438/Connect-C-to-MySQL

Sign up to request clarification or add additional context in comments.

4 Comments

Already checked this post. Also, the string replacement suggested didn't work.
Is MySQL running on the default port (3306)?
Yes, the service is running on port 3306.
Yes it solved my problem, the problem was that I was using the wrong classes, which as you stated are used for the Microsoft's MySQL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.