我有一个由本地数据库支持的Web服务,当托管它的计算机连接到网络时一切都很好,当我断开网络电缆并访问相同的Web方法时,我得到一个例外:
2014-11-19 13:46:24,151 DEBUG Sage.Client.Core.Web.ActionFilters.LogExceptionsAttribute System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
at System.Data.DataSet.EnableConstraints()
at System.Data.DataSet.set_EnforceConstraints(Boolean value)
at System.Data.DataTable.EndLoadData()
at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
at System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at Microsoft.Practices.EnterpriseLibrary.Data.Database.DoLoadDataSet(IDbCommand command, DataSet dataSet, String[] tableNames)
at Microsoft.Practices.EnterpriseLibrary.Data.Database.LoadDataSet(DbCommand command, DataSet dataSet, String[] tableNames)
at Microsoft.Practices.EnterpriseLibrary.Data.Database.LoadDataSet(DbCommand command, DataSet dataSet, String tableName)
at Sage.MMSAdmin.DBLayer.SessionHelper.GetSession(String sessionIdentifier)
at Sage.MMSAdmin.DBLayer.SessionHelper.SessionInfo(String sessionIdentifier)
at Sage.MMSAdmin.DBLayer.SAA.SAAAPI.GetSessionContextData(String sessionID)
at Sage.MMS.SAA.Client.InProcessProxy.SAAInProcessProxy.GetSessionContextData(String sessionID)
at Sage.Client.Core.Web.ActionFilters.RequiresValidCompanyAttribute.FetchContextData(String sessionID)
at Sage.Client.Core.Web.ActionFilters.RequiresValidCompanyAttribute.ValidateSession(ActionDescriptor actionDescriptor, HttpContextBase httpContext)
at Sage.Client.Core.Web.Attributes.ClaimsAuthorizeAttribute.OnAuthorization(AuthorizationContext filterContext)
at System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__19(AsyncCallback asyncCallback, Object asyncState)
这似乎与身份验证有关,但是我无法理解为什么在没有网络连接的情况下,如果成功运行,这会失败。
数据库是SQLServer2012。
非常感谢任何建议或指针
答案 0 :(得分:0)
问题在于表中的数据,在标记为NOT NULL的字段中存在空值,因此dataAdapter无法填充此数据并因为现有数据不满足而引发异常在表上设置的约束(数据模型)。
问题是由直接用于将数据插入表中的sql代码引起的,因此在插入数据之前代码没有检查约束(另外数据可能在约束之前存在)