无法使用实体框架从ASP.NET MVC连接到SQL Server

编程入门 行业动态 更新时间:2024-10-24 20:17:34
本文介绍了无法使用实体框架从ASP.NET MVC连接到SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是MVC应用程序的新手。我的问题是在我尝试连接到Sql Server2008时。这给了我错误: -

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'.

项目名称: - rsbenggmvc 上下文类: - RsbEnggContext 服务器名称: - DEEPAK-PC \ DEEPAK 无密码。 我是什么尝试过: 在我的HomeController索引中的行动是: - 公共ActionResult索引(int id) { RsbEnggContext rsbcontext = new RsbEnggContext(); BusinessDetails bdetails = rsbcontext.businessdetails.Single(bd => bd.ID == id); 返回查看(bdetails); } 在我的Index.cshtml中调用如: - @model rsbenggmvc.Models.DBModel.BusinessDetails @ Model.Clients 商业详情型号: - 名称空间rsbenggmvc.Models.DBModel { [表(TblBusinessDetails)) ] 公共类BusinessDetails { public int ID {get;组; } public int Products {get;组; } public int Clients {get;组; } public int比较{get;组; } public int Shares {get;组; } } } RsbEnggContext.cs分类: - 名称空间rsbenggmvc.Models { 公共类RsbEnggContext:DbContext { public DbSet< businessdetails> businessdetails {get;组; } } } 在Global.asax.cs课程中我添加了这个: - Database.SetInitializer< rsbenggmvc.models.rsbenggcontext>(null); 最后我的Web.Config文件的coonectionstring为: - < connectionstrings> < add name =DefaultConnectionconnectionstring =Data Source = DEEPAK-PC\SQLEXPRESS; AttachDBFilename = | DataDirectory | aspnetdb.mdf; User Instance = true; Initial Catalog = rsbengg; Persistent Security Info = True; Integrated Security = SSPIprovidername =System.Data.SqlClient> < add name =DatabaseEntitiesconnectionstring =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 = EntityFrameworkprovidername = System.Data.EntityClient> 但我收到此错误: - 无法打开登录请求的数据库rsbenggmvc.Models.RsbEnggContext。登录失败。 用户'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....

推荐答案

真的没有任何帮助。它归结为您阅读SQL Server安全性并了解它的工作原理以及如何设置它。你不可能有人只是在论坛帖子中给你一个模糊,它会神奇地工作。 错误非常清楚。 SQL Server不知道您是谁,因为您的帐户不在其自己的帐户列表中或在其信任的目录中。 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.

更多推荐

无法使用实体框架从ASP.NET MVC连接到SQL Server

本文发布于:2023-11-15 04:21:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1591103.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   实体   框架   ASP   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!