I'm New to MVC Application . My problem is while I'm trying to connect to Sql Server2008 . This is giving me the error :-
Cannot open database "rsbenggmvc.Models.RsbEnggContext" requested by the login. The login failed.
Login failed for user 'DEEPAK-PC\DEEPAK'.
Project Name :- rsbenggmvc
Context Class:- RsbEnggContext
Server Name :- DEEPAK-PC\DEEPAK
No Password.
What I have tried:
In My HomeController Index Action is:-
public ActionResult Index(int id)
{
RsbEnggContext rsbcontext = new RsbEnggContext();
BusinessDetails bdetails = rsbcontext.businessdetails.Single(bd => bd.ID == id);
return View(bdetails);
}
Calling in My Index.cshtml like:-
@model rsbenggmvc.Models.DBModel.BusinessDetails
@Model.Clients
BusinessDetails Model :-
namespace rsbenggmvc.Models.DBModel
{
[Table("TblBusinessDetails")]
public class BusinessDetails
{
public int ID { get; set; }
public int Products { get; set; }
public int Clients { get; set; }
public int Compares { get; set; }
public int Shares { get; set; }
}
}
RsbEnggContext.cs Class:-
namespace rsbenggmvc.Models
{
public class RsbEnggContext : DbContext
{
public DbSet<businessdetails> businessdetails { get; set; }
}
}
In Global.asax.cs Class I've added this :-
Database.SetInitializer<rsbenggmvc.models.rsbenggcontext>(null);
Finally my Web.Config file has coonectionstring as:-
<connectionstrings>
<add name="DefaultConnection" connectionstring="Data Source=DEEPAK-PC\SQLEXPRESS;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true; Initial Catalog=rsbengg;Persistent Security Info=True; Integrated Security=SSPI" providername="System.Data.SqlClient">
<add name="DatabaseEntities" connectionstring="metadata=res://*/ContactModel.csdl|res://*/ContactModel.ssdl|res://*/ContactModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\Database.mdf;integrated security=True;user instance=True;MultipleActiveResultSets=True;App=EntityFramework"" providername="System.Data.EntityClient">
But I get this error:-
Cannot open database "rsbenggmvc.Models.RsbEnggContext" requested by the login. The login failed.
Login failed for user 'DEEPAK-PC\DEEPAK'.
PLEASE HELP....