1
I have a problem with my MVC Asp.Net. I created the Connection String inside Webconfig,
<connectionStrings>
<add name="connSql"
providerName="System.Data.SqlClient"
connectionString="Data Source=localhost;
Initial Catalog=CarnetAdresse;
Integrated Security=True" />
</connectionStrings>
then created the Getlist() method within the "Contact" Template to bring 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 he gives me an Exception every time I try to run the program:
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.
Detail: Use Sqlserver 2012. On the teacher’s computer he used SQLEXPRESS and it worked, but in my nothing to work. I have deleted the created database other times, already modified the names of the connection string, rewrote the code... and nothing yet
– Marcelo Medeiros dos Santos
Another thing I tried: I added a rule in Windows Firewall to allow port 1433 for SQL SERVER. Firewall allow port 1433 for SQL Server Link: https://blogs.technet.microsoft.com/danstolts/2011/06/how-to-open-firewall-port-1433-for-sql-server-database-engine-for-use-with-scom-or-thinanyg-else/
– Marcelo Medeiros dos Santos