我刚刚在Windows共享主机上部署了我的MVC Web应用程序。每当我做一些需要与数据库通信的事情时,我就会一直收到NullReferenceException错误。我注意到,如果我绕过使用上下文类并使用方法内的Sql连接(如在SQLConnection,SqlCommand,SQLAdapter中)等,它会在数据库中找到数据。但是使用普通实体框架仍会产生错误。请注意,这只发生在实时站点中,而不是在Visual Studio中以调试模式运行时。
有人可以帮忙吗?我觉得这与我的主人有关。
更新
这是我访问我的一个模特时遇到的错误。
[NullReferenceException:对象引用未设置为对象的实例。]
ASP._Page_Views_InvoiceAdmin_Index_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 viewContext,TextWriter writer,Object instance)+256
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext,TextWriter writer)+107
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)+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 preContext,Func 1 continuation) +245
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList
1过滤器,ActionResult actionResult)+176
System.Web.Mvc.Async。&lt;&gt; c_ DisplayClass2a.b _20()+75
System.Web.Mvc.Async。&lt;&gt; 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__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>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。&lt;&gt; 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__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>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.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)+9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+9628700
System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&amp; completedSynchronously)+155
在我的cshtml视图中导致此问题的代码是@foreach (var item in Model)
我的主机的信任级别是中等的,我应该添加。
更新2
好的,我只是尝试从Visual Studio部署一个全新的MVC应用程序,这在尝试访问模型时没有给我任何错误(我制作了一个简单的学生模型并创建了一个新的&#34;学生&#34;在数据库,在我的实际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; }
}
}
我的连接字符串是: