I create a new project and create a simple project working with CodeFirstApproach
First Create a student class and then create a context class(communicate between database and table) and write a below code in web.config
Sql Server authentication
username: sa
password: s123
web.config
<!--CodeFirstAproach-->
<connectionStrings> //something is wrong here
<add name="conn" connectionString="Server=.\JSdique;database=codefirst;User Id=sa;Password=s123" providerName="System.Data.SqlClient" />
</connectionStrings>
and then create a Home Controller and then Create a view
ContextClass
public class ContextClass : DbContext
{
public ContextClass() : base("conn") { }
public DbSet<Student> students { get; set; }
}
HomeController
public class HomeController : Controller
{
ContextClass db = new ContextClass();
// GET: Home
public ActionResult Index()
{
var data = db.students.ToList();
return View(data);
}
}
Error:
Additional information: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
How to solve this error?
I Refer this Link:https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/authentication-in-sql-server