我有以下连接字符串:MySQL连接字符串不工作
Data Source=localhost;UserID=root;Password=;Database=eyebus;
当我尝试连接到数据库,我得到一个错误说,也许是服务器未找到或无法访问。这个字符串有什么问题?
我也尝试了其他字符串/单词,我在互联网上找到,但没有一个真正起作用。
此外,问题不在于服务器,因为它可以被其他应用程序访问。
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;
}
}
}
您使用的数据库连接提供程序是什么? – 2013-03-01 19:15:10
看看这篇文章:http://stackoverflow.com/questions/10505952/mysql-connection-string-is-not-working-in-c-sharp – 2013-03-01 19:15:37
MySql.Data.MySqlClient。我已经看过那篇文章,但提出的解决方案并没有解决我的问题。 – 2013-03-01 19:16:38