Estou com um problema na minha aplicação MVC Asp.Net. Criei a String de conexão dentro do Webconfig,
<connectionStrings>
<add name="connSql"
providerName="System.Data.SqlClient"
connectionString="Data Source=localhost;
Initial Catalog=CarnetAdresse;
Integrated Security=True" />
</connectionStrings>
depois criei o método GETList() dentro do Modelo "Contact" para trazer a lista do banco de dados :
public static List<Contact> GetList()
{
string connexionSql = ConfigurationManager.ConnectionStrings["connSql"].ConnectionString;
using (SqlConnection cnx = new SqlConnection(connexionSql))
{
string requete = "SELECT * FROM Contact";
SqlCommand cmd = new SqlCommand(requete, cnx);
cmd.CommandType = System.Data.CommandType.Text;
try
{
cnx.Open();
SqlDataReader dataReader = cmd.ExecuteReader();
List<Contact> contactList = new List<Contact>();
while (dataReader.Read())
{
Contact c = new Contact();
c.id = (int)dataReader["id"];
c.Nom = (string)dataReader["Nom"];
c.Telephone = (string)dataReader["Telephone"];
c.Courriel = (string)dataReader["Courriel"];
c.DateNaissance = (DateTime)dataReader["DateNaissance"];
c.CodePostal = (string)dataReader["CodePostal"];
contactList.Add(c);
}
dataReader.Close();
return contactList;
}
finally
{
cnx.Close();
}
}
}
e ele me dá uma exception em todo momento que tento executar o programa:
Une exception de type 'System.NullReferenceException' s'est produite dans CarnetAdresse.dll mais n'a pas été gérée dans le code utilisateur
Informations supplémentaires : Object reference not set to an instance of an object.