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;
}
}
}