最近我将DateofBirth添加到表中。在本地,它可以正常工作。 我还将更新客户端的数据库和实体数据模型。但是会出现错误。
无效的列名“ DateofBirth”。 说明:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。
异常详细信息:System.Data.SqlClient.SqlException:无效的列名'DateofBirth'。
堆栈跟踪:
[SqlException(0x80131904):无效的列名'DateofBirth'。]
System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔值breakConnection,操作1 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, TaskCompletionSource
1完成,Int32超时,任务和任务,布尔值和usedCache,布尔值asyncWrite,布尔值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.InternalDispatcher 1.Dispatch(TTarget target, Func
3操作,TInterceptionContext拦截上下文,Action 3 executing, Action
3执行)+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上下文,ObjectParameterCollection parameterValues)+1014
System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func 1 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(Func
1操作)+234
System.Data.Entity.Core.Objects.ObjectQuery 1.GetResults(Nullable
1 forMergeOption)+354
System.Data.Entity.Core.Objects.ObjectQuery 1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() +30
System.Data.Entity.Internal.LazyEnumerator
1.MoveNext()+39
System.Collections.Generic.List 1..ctor(IEnumerable
1个集合)+436
System.Linq.Enumerable.ToList(IEnumerable 1 source) +70
BLAST.Controllers.EmployeeVarityReportController.EmpDetails() +5302
lambda_method(Closure , ControllerBase , Object[] ) +87
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary
2个参数)+229
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext,ActionDescriptor actionDescriptor,IDictionary 2 parameters) +35
System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +39
System.Web.Mvc.Async.WrappedAsyncResult
2.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.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +73
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52
System.Web.Mvc.Async.WrappedAsyncVoid
1.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步骤,布尔值并已完成同步)+128
答案 0 :(得分:2)
该表中不存在该列,您必须运行迁移或使用其他方式来更新客户数据库
答案 1 :(得分:1)
基于堆栈跟踪,我怀疑您已在配置类中将 AutomaticMigrationsEnabled 设置为 false 。要解决此问题,您需要手动创建一个新的迁移文件。您可以在Nuget软件包管理器控制台中运行 Add-Migration 命令来创建新迁移。
答案 2 :(得分:0)
当我更新数据库中的表但尚未更新接口中的数据绑定或映射时,出现这种错误。在以数据绑定级别刷新我的数据源之后,一切正常。所以我猜这个错误是由数据库级别和接口级别的数据同步/更新引起的。因此,我必须做的是检查所有字段控制列表的映射。
答案 3 :(得分:0)
确保您的查询有正确的引用。 例如,
cmd.CommandText = "insert into student(id,name,dob) values("+id+","+name+","+dob+")";
是一种编写查询的异常绑定方式。 试试这个方法
cmd.CommandText = "insert into student(id,name,dob) values('"+id+"','"+name+"','"+dob+"')";