Data Context Class And Connection String For ASP.NET MVC5
Data Context Class:
public class UserDefineClass :DbContext
{
public DbSet<modelName> TableName{ get; set; }
}
For Example: I am using SQL Server 2008R2.My Database name is MNDB. Projects is the Table name for Project Model...
public class Mn:DbContext
{
public DbSet<Project> Projects{ get; set; }
}
or
public class Mn:DbContext
{
public System.Data.Entity.DbSet<SolutionName.Models.Project> Projects{ get; set; }
}
Connection String:
<connectionStrings>
<add name="Mn" connectionString="data source=.\SQLExpress;Initial Catalog=MNDB;Integrated Security=true" providerName="System.Data.sqlClient"/>
</connectionStrings>
For SQL Authentication e.g. User Id=sa , password=1234 and Data source name:192.168.10.15\SS8
<connectionStrings>
<add name="Mn" connectionString="Data Source=192.168.10.15\SS8;Initial Catalog=MNDB;User ID=sa;Password=1234" providerName="System.Data.SqlClient" />
</connectionStrings>
No comments:
Post a Comment