I have a problem with my Asp.Net MVC application. I created the Connection String within Webconfig,
<connectionStrings>
<add name="connSql"
providerName="System.Data.SqlClient"
connectionString="Data Source=localhost;
Initial Catalog=CarnetAdresse;
Integrated Security=True" />
</connectionStrings>
Then I created the GETList () method inside the "Contact" Model to bring up the database list:
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();
}
}
}
and it gives me an exception at all times that I try to run the program:
Uniqueness of type 'System.NullReferenceException' s'est produite dans CarnetAdresse.dll more n'a pas été gérée dans le code utilisateur
Supplementary information: Object reference not set to an instance of an object.