【问题标题】:Invalid column name .Don't Know Why?列名无效。不知道为什么?
【发布时间】:2019-02-20 12:25:44
【问题描述】:

最近我将 DateofBirth 添加到表中。在本地,它工作正常。 我还更新了客户的数据库和实体数据模型。但出现错误。

列名“出生日期”无效。 说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.Data.SqlClient.SqlException:列名“出生日期”无效。

堆栈跟踪:

[SqlException (0x80131904): 列名 'DateofBirth' 无效。] System.Data.SqlClient.SqlConnection.OnError(SqlException 异常,布尔 breakConnection,Action1 wrapCloseInAction) +3305692 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +736 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4061 System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +90 System.Data.SqlClient.SqlDataReader.get_MetaData() +99 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) +604 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) +3303 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 完成,Int32 超时,Task& 任务,Boolean& usedCache,Boolean asyncWrite,Boolean inRetry)+667 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String 方法) +83 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior 行为,字符串方法)+301 System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch(TTarget target, Func3 操作,TInterceptionContext 拦截上下文,Action3 executing, Action3 执行)+104 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand 命令,DbCommandInterceptionContext 拦截上下文)+499 System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior 行为) +36

[EntityCommandExecutionException:执行命令定义时出错。有关详细信息,请参阅内部异常。] System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand,CommandBehavior 行为)+125 System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute(ObjectContext context, ObjectParameterCollection parameterValues) +1014 System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +459 System.Data.Entity.Core.Objects.<>c__DisplayClass7.<GetResults>b__5() +203 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func1 操作)+234 System.Data.Entity.Core.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption) +354 System.Data.Entity.Core.Objects.ObjectQuery1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() +30 System.Data.Entity.Internal.LazyEnumerator1.MoveNext() +39 System.Collections.Generic.List1..ctor(IEnumerable1 个集合)+436 System.Linq.Enumerable.ToList(IEnumerable1 source) +70 BLAST.Controllers.EmployeeVarityReportController.EmpDetails() +5302 lambda_method(Closure , ControllerBase , Object[] ) +87 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 参数) +229 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +35 System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +39 System.Web.Mvc.Async.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) +77 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3d() +72 System.Web.Mvc.Async.c__DisplayClass46.b__3f() +387 System.Web.Mvc.Async.c__DisplayClass46.b__3f() +387 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.c__DisplayClass2b.b__1c() +38 System.Web.Mvc.Async.c__DisplayClass21.b__1e(IAsyncResult asyncResult) +188 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38 System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +73 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +39 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38 System.Web.Mvc.MvcHandler.b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +43 System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +73 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +602 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep 步骤) +195 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +128

【问题讨论】:

    标签: asp.net-mvc entity-framework client-server stack-trace


    【解决方案1】:

    表中不存在该列,您必须运行迁移或使用其他方式更新客户数据库

    【讨论】:

      【解决方案2】:

      根据堆栈跟踪,我怀疑您在配置类中将 AutomaticMigrationsEnabled 设置为 false。要解决此问题,您需要手动创建一个新的迁移文件。您可以在 Nuget 包管理器控制台中运行 Add-Migration 命令创建新的迁移。

      Here is a tutorial on how to create a new migration script.

      【讨论】:

        【解决方案3】:

        当我在数据库中更新我的表但尚未在我的界面中的数据绑定或映射中时,我得到了这种错误。在我的数据绑定级别刷新我的数据源后,一切顺利。所以我猜这个错误是由数据库级别和接口级别的数据同步/更新引起的。所以,我要做的就是检查所有的字段控件-列表映射。

        【讨论】:

          【解决方案4】:

          确保您的查询有正确的引用。 例如,

          cmd.CommandText = "insert into student(id,name,dob) values("+id+","+name+","+dob+")";
          

          是一种编写查询的异常绑定方式。 用这种方法试试

          cmd.CommandText = "insert into student(id,name,dob) values('"+id+"','"+name+"','"+dob+"')";
          

          【讨论】:

          • 这与无效的列名有什么关系?
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-03-18
          • 2012-12-01
          • 1970-01-01
          • 2013-09-13
          • 2015-01-22
          • 2023-04-06
          • 1970-01-01
          相关资源
          最近更新 更多