当前位置:编程学习 > C#/ASP.NET >>

vs2010发布的网站不能访问数据库

我在vs2010下调试网站一切正常。
然而发布后的网站每次运行在需要访问数据库时,就抛异常Object reference not set to an instance of an object.

有没有人遇到类似问题? --------------------编程问答-------------------- 我用.netTier生成的数据访问层和Service层 --------------------编程问答-------------------- 对象没有实例化,是数据问题,你检查一下 --------------------编程问答-------------------- 贴出报错的那几行代码。

检查下有没有对象为null。 --------------------编程问答-------------------- [NullReferenceException: Object reference not set to an instance of an object.]
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingConfigurationView.GetExceptionPolicyData(String policyName) +141
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyCustomFactory.GetConfiguration(String id, IConfigurationSource configurationSource) +68
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) +107
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +176
   Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +104
   Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +290
   Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +104
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +206
   Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) +372
   Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) +142
   Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies) +132
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp(IReadWriteLocator locator, String id, IConfigurationSource configurationSource) +359
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.LocatorNameTypeFactoryBase`1.Create(String name) +111
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName) +93

[ExceptionHandlingException: Object reference not set to an instance of an object.]
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName) +317
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName) +193
   ChengDuShiYuan.Objects.Services.DomainUtil.HandleException(Exception e, String policyName) +68
   ChengDuShiYuan.Objects.Services.UserServiceBase.Find(IFilterParameterCollection parameters, String orderBy, Int32 start, Int32 pageLength, Int32& count) +325
   ChengDuShiYuan.Objects.Services.UserServiceBase.Find(IFilterParameterCollection parameters, String orderBy) +69
   ChengDuShiYuan.Objects.Services.UserServiceBase.Find(IFilterParameterCollection parameters) +47
   ChengDuShiYuanWeb.Service.ServiceOfUser.Authenticate(String name, String password) in C:\Users\cloud\Desktop\Cloud\Projects\ExcelWeb\vs2010sol\ChengDuShiYuan\ChengDuShiYuanWeb\Code\Service\ServiceOfUser.cs:25
   ChengDuShiYuanWeb.Login.btnLogin_Click(Object sender, EventArgs e) in C:\Users\cloud\Desktop\Cloud\Projects\ExcelWeb\vs2010sol\ChengDuShiYuan\ChengDuShiYuanWeb\Login.aspx.cs:54
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563 --------------------编程问答--------------------
[NullReferenceException: Object reference not set to an instance of an object.]
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingConfigurationView.GetExceptionPolicyData(String policyName) +141
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyCustomFactory.GetConfiguration(String id, IConfigurationSource configurationSource) +68
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) +107
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +176
   Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +104
   Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +290
   Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +104
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +206
   Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) +372
   Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) +142
   Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies) +132
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp(IReadWriteLocator locator, String id, IConfigurationSource configurationSource) +359
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.LocatorNameTypeFactoryBase`1.Create(String name) +111
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName) +93

[ExceptionHandlingException: Object reference not set to an instance of an object.]
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName) +317
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName) +193
   ChengDuShiYuan.Objects.Services.DomainUtil.HandleException(Exception e, String policyName) +68
   ChengDuShiYuan.Objects.Services.UserServiceBase.Find(IFilterParameterCollection parameters, String orderBy, Int32 start, Int32 pageLength, Int32& count) +325
   ChengDuShiYuan.Objects.Services.UserServiceBase.Find(IFilterParameterCollection parameters, String orderBy) +69
   ChengDuShiYuan.Objects.Services.UserServiceBase.Find(IFilterParameterCollection parameters) +47
   ChengDuShiYuanWeb.Service.ServiceOfUser.Authenticate(String name, String password) in C:\Users\cloud\Desktop\Cloud\Projects\ExcelWeb\vs2010sol\ChengDuShiYuan\ChengDuShiYuanWeb\Code\Service\ServiceOfUser.cs:25
   ChengDuShiYuanWeb.Login.btnLogin_Click(Object sender, EventArgs e) in C:\Users\cloud\Desktop\Cloud\Projects\ExcelWeb\vs2010sol\ChengDuShiYuan\ChengDuShiYuanWeb\Login.aspx.cs:54
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
--------------------编程问答-------------------- 最纠结的问题是, 在vs2010调试时不会出现这个错误 --------------------编程问答-------------------- 我感觉的是你访问了数据库一个对象,这个对象返回null,而你又没有判断这个对象为null的处理,而直接访问了对象的属性,以致报错. --------------------编程问答-------------------- (String name, String password) in C:\Users\cloud\Desktop\Cloud\Projects\ExcelWeb\vs2010sol\ChengDuShiYuan\ChengDuShiYuanWeb\Code\Service\ServiceOfUser.cs:25
   ChengDuShiYuanWeb.Login.btnLogin_Click(Object sender, EventArgs e) in C:\Users\cloud\Desktop\Cloud\Projects\ExcelWeb\vs2010sol\ChengDuShiYuan\ChengDuShiYuanWeb\Login.aspx.cs:54


这些代码你应该认真看,应该是在登录的时候就报错了.已经具体到哪一行了,那一行读取什么数据,你检查一下 --------------------编程问答-------------------- 你用什么数据库? --------------------编程问答-------------------- 找到 ServiceOfUser.cs 25行,看用到哪些变量,逐个进行为空判断 --------------------编程问答-------------------- --------------------编程问答-------------------- 用的什么数据库呢?数据库访问组件是不是有问题 --------------------编程问答-------------------- 除
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,