Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I'm New to MVC Application . My problem is while I'm trying to connect to Sql Server2008 . This is giving me the error :-
C#
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....
Posted
Updated 12-May-16 8:05am
Comments
ZurdoDev 12-May-16 13:34pm    
How can we help? The error is pretty clear.

1 solution

There's really nothing to help with. It comes down to you reading up on SQL Server security and understanding how it works and how to set it up. There is no way you're going to have someone just give you a blurb in a forum post and it'll magically work.

The error is pretty clear. The SQL Server doesn't know who you are since your account isn't in either its own list of accounts or in a directory that it trusts.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900