Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.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
Asp.net mvc MVC Web应用程序未与数据源通信_Asp.net Mvc_Sql Server 2008_Entity Framework_Asp.net Mvc 4_Visual Studio 2012 - Fatal编程技术网

Asp.net mvc MVC Web应用程序未与数据源通信

Asp.net mvc MVC Web应用程序未与数据源通信,asp.net-mvc,sql-server-2008,entity-framework,asp.net-mvc-4,visual-studio-2012,Asp.net Mvc,Sql Server 2008,Entity Framework,Asp.net Mvc 4,Visual Studio 2012,我刚刚在windows共享主机上部署了我的MVC web应用程序。每当我做一些需要与数据库通信的事情时,就会不断收到NullReferenceException错误。我注意到,如果我绕过使用context类并使用in-Sql连接方法(如SQLConnection、SqlCommand、SQLAdapter)等,它会在数据库中查找数据。但是使用普通实体框架仍然会产生错误。请注意,这仅在实时站点中发生,而不是在VisualStudio中以调试模式运行时发生 有人能帮忙吗?我觉得这和我的主人有关 更新

我刚刚在windows共享主机上部署了我的MVC web应用程序。每当我做一些需要与数据库通信的事情时,就会不断收到NullReferenceException错误。我注意到,如果我绕过使用context类并使用in-Sql连接方法(如SQLConnection、SqlCommand、SQLAdapter)等,它会在数据库中查找数据。但是使用普通实体框架仍然会产生错误。请注意,这仅在实时站点中发生,而不是在VisualStudio中以调试模式运行时发生

有人能帮忙吗?我觉得这和我的主人有关

更新

这是我在访问我的一个模型时遇到的错误

[NullReferenceException:对象引用未设置为对象的实例。] ASP.\页面\视图\发票管理员\索引\ cshtml.Execute()位于f:\Domains\ROM30\proopt.co.za\proopt.co.za\proopt.co.za\Views\InvoiceAdmin\Index.cshtml:40 System.Web.WebPages.WebPageBase.ExecutePageHierarchy()+197 System.Web.Mvc.WebViewPage.ExecutePageHierarchy()+103 System.Web.WebPages.StartPage.RunPage()+17 System.Web.WebPages.StartPage.ExecutePageHierarchy()+62 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext-pageContext、TextWriter-writer、WebPageRenderingBase-startPage)+76 System.Web.Mvc.RazorView.RenderView(ViewContext、TextWriter、Object实例)+256 System.Web.Mvc.buildmanager compiledview.Render(ViewContext、TextWriter)+107 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext上下文)+291 System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext ControllerContext,ActionResult ActionResult)+13 System.Web.Mvc.c_DisplayClass1a.b_17()+23 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter筛选器,ResultExecutingContext预文本,Func
1 continuation)+245
System.Web.Mvc.c__DisplayClass1c.b__19()+22
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext ControllerContext,IList
1过滤器,ActionResult ActionResult)+176 System.Web.Mvc.Async.c_DisplayClass2a.b_20()+75 System.Web.Mvc.Async.c_DisplayClass25.b_22(IAsyncResult asyncResult)+99 System.Web.Mvc.Async.WrappedAsyncResult
1.End()+50
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)+27
System.Web.Mvc.c__;u displayClassId.b__u18(IAsyncResult asyncResult)+14
System.Web.Mvc.Async.c__显示类4.b__3(IAsyncResult ar)+23
System.Web.Mvc.Async.WrappedAsyncResult
1.End()+55 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+39 System.Web.Mvc.Async.c_DisplayClass4.b_3(IAsyncResult ar)+23 System.Web.Mvc.Async.WrappedAsyncResult
1.End()+55
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)+29
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)+10
System.Web.Mvc.c__;u DisplayClass8.b__;u 3(IAsyncResult asyncResult)+25
System.Web.Mvc.Async.c__显示类4.b__3(IAsyncResult ar)+23
System.Web.Mvc.Async.WrappedAsyncResult
1.End()+55 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+31 System.Web.Mvc.MvcHandler.System.Web.IHTTPassynchandler.EndProcessRequest(IAsyncResult结果)+9 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+9628700 System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+155

在我的cshtml视图中导致这种情况的代码是
@foreach(模型中的var项)

我应该补充一句,我的主人的信任度是中等的

更新2

好的,我刚刚尝试从Visual Studio部署一个全新的MVC应用程序,在尝试访问模型时没有出现任何错误(我创建了一个简单的学生模型,并在数据库中创建了一个新的“学生”,这在我的实际MVC应用程序中不起作用。有什么想法吗

更新3

下面是我的DbContext类,它填充了我的模型:

namespace ProOptInteractive.Models
{
    public class OnlineEntities : DbContext
    {
        public DbSet<Product> Products { get; set; }
        public DbSet<Service> Services { get; set; }
        public DbSet<ProductCategory> ProductCategories { get; set; }
        public DbSet<ServiceCategory> ServiceCategories { get; set; }
        public DbSet<Supplier> Suppliers { get; set; }
        public DbSet<Cart> Carts { get; set; }
        public DbSet<Order> Orders { get; set; }
        public DbSet<OrderDetail> OrderDetails { get; set; }
        public DbSet<Callout> Callouts { get; set; }
        public DbSet<CalloutDetail> CalloutDetails { get; set; }
        public DbSet<Invoice> Invoices { get; set; }
        public DbSet<Client> Clients { get; set; }
        public DbSet<LiabilityRate> LiabilityRates { get; set; }
        public DbSet<Technician> Technicians { get; set; }
        public DbSet<QualificationLevel> QualificationLevels { get; set; }
    }
}
namespace ProOptInteractive.Models
{
公共类OnlineEntities:DbContext
{
公共数据库集产品{get;set;}
公共数据库集服务{get;set;}
公共数据库集ProductCategories{get;set;}
公共数据库集服务类别{get;set;}
公共数据库集提供者{get;set;}
公共DbSet Carts{get;set;}
公共数据库集命令{get;set;}
公共DbSet OrderDetails{get;set;}
公共数据库集调用{get;set;}
公共数据库集详图索引{get;set;}
公共数据库集{get;set;}
公共数据库集客户端{get;set;}
公共DbSet LiabilityRates{get;set;}
公共数据库集{get;set;}
公共DbSet限定级别{get;set;}
}
}

我的连接字符串是:

向我们显示异常消息和导致异常的代码也需要查看相关代码。异常只是向我们显示您的模型为空。您需要向我们显示填充模型的代码,向我们显示您的连接字符串(确保取出任何敏感信息,如用户名和密码),等等。模型为空的事实不是错误。这不是填充模型的代码,这只是dbcontext的定义。我们需要查看您的代码。我不认为我的代码有任何问题,就像我在本地调试模式下运行程序一样,它正常地从远程数据库中提取数据。