我的MVC应用程序在尝试访问数据库中的任何表时返回SqlExceptions.
异常详细信息:System.Data.SqlClient.SqlException:无效的对象名称'dbo.Projects'.
我的应用程序是我们的数据层linq.
如果我使用一个旧的DLL它工作正常,(这似乎不是数据库的问题)只是我上传的这个最新的应用程序DLL.
细节
[SqlException(0x80131904):无效的对象名称'dbo.Projects'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception,Boolean breakConnection)+1950890
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception,Boolean breakConnection) +4846875
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)+194 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)+2392
System.Data.SqlClient. SqlDataReader.ConsumeMetaData()+ 33
System.Data.SqlClient.SqlDataReader.get_MetaData()+83
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,String resetOptionsString)+297
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds (的CommandBehavior cmdBehavior,runBehavior runBehavior,布尔returnStream,布尔异步)954
System.Data.SqlClient.SqlCommand.RunExecuteReader(联合 mmandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String method,DbAsyncResult result)+162
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String method)+32
System.Data.SqlClient.SqlCommand.ExecuteReader (CommandBehavior behavior,String method)+141
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)+12 System.Data.Common.DbCommand.ExecuteReader()+12
System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query,QueryInfo queryInfo,IObjectReaderFactory factory,Object [] parentArgs,Object [] userArgs,ICompiledSubQuery [] subQueries,Object lastResult)+975
System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query,QueryInfo [] queryInfos,IObjectReaderFactory factory ,对象[] userArguments,ICompiledSubQuery []子查询)113
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(表达式查询)344
System.Data.L inq.DataQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +35 System.Linq.Buffer1..ctor(IEnumerable的1..ctor(IEnumerable的1..ctor(IEnumerable的1源)61 Mezza_crm.Controllers.ProjectsController.GetProjectList(NameValueCollection中形式)在C:\ mezza_crm\mezza_crm \控制器\ ProjectsController.cs :C:\ mezza_crm\mezza_crm\Controllers\ProjectsController.cs中的164 Mezza_crm.Controllers.ProjectsController.List():53 lambda_method(ExecutionScope,ControllerBase,Object [])+39 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller) ,对象[]参数)17 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary的2个参数)24 System.Web.Mvc.<> c__DisplayClassa.b__7()52 System.Web.Mvc.ControllerActionInvoker. InvokeActionMethodFilter(IActionFilter过滤器,ActionExecutingContext preContext,Func 1过滤器,ActionDescriptor actionDescriptor,IDictionary`2参数)+192 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext,String actionName)+399 System.Web.Mvc.Co ntroller.ExecuteCore()126 System.Web.Mvc.ControllerBase.Execute(RequestContext的RequestContext的)27 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext的RequestContext的)7 System.Web.Mvc .MvcHandler.ProcessRequest(HttpContextBase httpContext)+151 System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext)+57 System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext)+7 System.Web. CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()181 System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔逻辑completedSynchronously)751 source) +247 System.Linq.<GetEnumerator>d__0.MoveNext() +108
System.Linq.Buffer1 source) +259
System.Linq.<GetEnumerator>d__0.MoveNext() +108
System.Collections.Generic.List1 collection) +7665172 System.Linq.Enumerable.ToList(IEnumerable2 parameters) +178
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary1 continuation) +254
System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList
Joe*_*Joe 53
检查连接字符串中的Initial Catalog参数.可能是您的代码正在查找Projects对象的错误数据库.
例如,如果您以只传送master-database表的子集的方式进行数据库同步设置,那么如果Linq to SQL期望所有表都在连接字符串指向的数据库中,则会遇到此错误.
小智 14
我已经看到,当您定义结果实体时,如果您处理不同的方案,新版本可以更好地按以下方式定义它们,我遇到了类似的问题
您必须添加 System.ComponentModel.DataAnnotations.Schema
using System.ComponentModel.DataAnnotations.Schema;
[Table("InstitucionesMilitares", Schema = "configuracion")]
Run Code Online (Sandbox Code Playgroud)
您是否有权访问您正在查询的 SQL Server?你能在那里看到一个名为 dbo.Projects 的表或视图吗?如果没有,那将是一个看的好地方。
Linq to SQL 在数据库和应用程序之间创建一个对象映射。如果您正在部署的新 DLL 不再与数据库匹配,那么这就是您希望得到的那种错误。
您的开发环境和部署环境之间可能有不同的数据库模式吗?
小智 6
如果数据库中已有 _MigrationHistory 表,请删除 (yourdatabseName > Tables > System Tables) 中的表,然后在包管理器控制台中运行以下命令
PM> update-database
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
104114 次 |
| 最近记录: |