Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC 4连接字符串可以';t登录_C#_Asp.net Mvc_Entity Framework_Asp.net Mvc 4 - Fatal编程技术网

C# MVC 4连接字符串可以';t登录

C# MVC 4连接字符串可以';t登录,c#,asp.net-mvc,entity-framework,asp.net-mvc-4,C#,Asp.net Mvc,Entity Framework,Asp.net Mvc 4,我正在使用MVC 4和Entity Framework 5.0创建一个网站。我希望有一个页面,用户可以在其中查看他的数据(姓名、电子邮件、年龄等)。问题是,当试图访问该数据库时,程序中断并返回 在内部异常中,它给出了以下错误: 我认为这可能是因为我在Web.Config中错误地定义了连接字符串 `add name="PerfilContexto" connectionString="metadata=res://*/ModeloBookmania.csdl|res://*/ModeloBookm

我正在使用MVC 4和Entity Framework 5.0创建一个网站。我希望有一个页面,用户可以在其中查看他的数据(姓名、电子邮件、年龄等)。问题是,当试图访问该数据库时,程序中断并返回

在内部异常中,它给出了以下错误:

我认为这可能是因为我在Web.Config中错误地定义了连接字符串

`add name="PerfilContexto" connectionString="metadata=res://*/ModeloBookmania.csdl|res://*/ModeloBookmania.ssdl|res://*/ModeloBookmania.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=C:\Users\teste.TAG000002717\Documents\BD.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />`
作为模型的“PerfilContexto”,我将其称为类Dbcontext

public class PerfilContext :DbContext
{
     public DbSet<Perfil>  Dados { get; set; } 
}

您为连接字符串设置了不正确的名称

您的dbcontext类名:PerfilContext

您的连接字符串名称:PerfilContexto

将connectionstring名称更改为PerfilContext或将此名称显式传递给基本构造函数:

 public class PerfilContext : DbContext
 { 
      public PerfilContext()
         :base("PerfilContexto")
      {
      }

      public DbSet<Perfil>  Dados { get; set; } 
 }
公共类PerfilContext:DbContext
{ 
公共PerfilContext()
:base(“PerfilContexto”)
{
}
公共DbSet Dados{get;set;}
}

您为连接字符串设置了不正确的名称

您的dbcontext类名:PerfilContext

您的连接字符串名称:PerfilContexto

将connectionstring名称更改为PerfilContext或将此名称显式传递给基本构造函数:

 public class PerfilContext : DbContext
 { 
      public PerfilContext()
         :base("PerfilContexto")
      {
      }

      public DbSet<Perfil>  Dados { get; set; } 
 }
公共类PerfilContext:DbContext
{ 
公共PerfilContext()
:base(“PerfilContexto”)
{
}
公共DbSet Dados{get;set;}
}

噢,db正在使用Windows身份验证登录方法噢,db正在使用Windows身份验证登录方法“-”Omg,谢谢兄弟。我仍然是这方面的新手(x)仍然,它没有运行。在控制器上,它给出异常错误,并给出一个附加信息。“其他信息:实体类型Perfil不是当前上下文模型的一部分。”请看这个:再次感谢bro;)。我来试试。我只是下载最新版本的Sql管理,在本地服务器上创建一个数据库。非常感谢兄弟。我一整天都在试图找出问题所在,而你在不到10分钟内就解决了。非常感谢兄弟。)没问题:)我很高兴能帮上忙“-”天哪,谢谢兄弟。我仍然是这方面的新手(x)仍然,它没有运行。在控制器上,它给出异常错误,并给出一个附加信息。“其他信息:实体类型Perfil不是当前上下文模型的一部分。”请看这个:再次感谢bro;)。我来试试。我只是下载最新版本的Sql管理,在本地服务器上创建一个数据库。非常感谢兄弟。我一整天都在试图找出问题所在,而你在不到10分钟内就解决了。非常感谢兄弟。)没问题:)我很高兴能帮上忙
    public ActionResult Perfil(int userid=1)

        if(Session["UserID"] == null)

            return View(); // if there's no session, it runs blank,cause in the view there's a code to redirect to homepage if there's no session.


       var ida=Session["UserID"]; //After login this variable keeps the user id
       userid = Convert.ToInt32(ida);//the varaible is converted to int
        PerfilContext contexto = new PerfilContext();
     /* gives error about "Perfil" wich is the model for the view*/ 
         Perfil conteXto = contexto.Dados.Single(perf=>perf.ID == userid);
        return View(conteXto);
    `
 public class PerfilContext : DbContext
 { 
      public PerfilContext()
         :base("PerfilContexto")
      {
      }

      public DbSet<Perfil>  Dados { get; set; } 
 }