我有以下連接字符串: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