I am new to ASP.NET MVC, I am facing this exception, the connection string looks perfect but still, the exception is raised, appreciate if anyone give me why is happening.
Thank you guys
Model 1
namespace MVCTwice.Models
{
public class StudentContext : DbContext
{
public DbSet<Student> studs { get; set; }
}
}
Model 2
namespace MVCTwice.Models
{
[Table("tblStudents")]
public class Student
{
public int id { get; set; }
public string name { get; set; }
public string gender { get; set; }
public string totalMarks { get; set; }
}
}
Action method
public ActionResult Index()
{
StudentContext studentContext = new StudentContext();
//Student emp = studentContext.studs.Select(emp=>emp.)
List<Student> emp=studentContext.studs.ToList();
return View(emp);
}
View
@model MVCTwice.Models.Student
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
@Model.gender
@Model.name
@Model.id
@Model.totalMarks
</div>
</body>
</html>
Exception
ConnectionString
<connectionStrings >
<add
name="myConnectionString"
connectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=LoginInfo;Data Source=.\SQLEXPRESS"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<connectionStrings>
<add name ="StudentContext "
connectionString ="server=.; database=here your database name; integrated security=SSPI"
providerName ="system.data.SqlClient"/>
</connectionStrings>
Here is your code but change your database name and then add it into the web.config file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With