Error (Connection String) Asp .Net MVC - Visual Studio 2013 and SQL Server 2012

1

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.

    
asked by anonymous 27.10.2016 / 18:57

1 answer

2

There are two web.config in a .net web application. One inside the root of the application and another in the root of the folder views. Is this code in which web.config? The right thing is to be in the web.config of the application root.

    
28.10.2016 / 18:23