请有人帮助我! 我有一个在Windows 2003上使用sql server 2005运行的应用程序。当我尝试在带有sql server 2000的Windows 2003上的其他服务器中部署这个应用程序时,应用程序的某些页面会显示以下消息:
Server Error in '/' Application.
Line 1: Incorrect syntax near '('.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near '('.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): Line 1: Incorrect syntax near '('.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1948826
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4844747
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, Boolean returnStream, Boolean async) +954
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior 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(CommandBehavior behavior) +10
System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +383
[EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details.]
System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +422
System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute(ObjectContext context, ObjectParameterCollection parameterValues) +745
System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +162
System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +45
System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +203
System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__1(IEnumerable`1 sequence) +40
System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle(IEnumerable`1 query, Expression queryRoot) +60
System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression) +109
System.Linq.Queryable.FirstOrDefault(IQueryable`1 source) +269
SebraeFE.Models.Repositories.InterestsRepository.DeleteInterests(Interests interestsToDelete) +418
SebraeFE.Models.Managers.InterestsManager.DeleteInterests(Interests interestsToDelete) +41
SebraeFE.Models.Facades.InterestsFacade.DeleteInterests(Interests interestsToDelete) +41
SebraeFE.Controllers.OportunidadeController.ApagarInteresse(Int32 Id) +265
lambda_method(ExecutionScope , ControllerBase , Object[] ) +78
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +178
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +24
System.Web.Mvc.<>c__DisplayClassa.<InvokeActionMethodWithFilters>b__7() +53
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +258
System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +258
System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +193
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +382
System.Web.Mvc.Controller.ExecuteCore() +123
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +23
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +144
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +54
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +406
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +76
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
未知的技术如下:
asp.net mvc 1
ADO.net和LINQ
请帮助我!
答案 0 :(得分:24)
使用xml编辑器打开您的模型.edmx,然后修改此
ProviderManifestToken="2008"
到
ProviderManifestToken="2000"
可能是linq .first()生成sql脚本'Top(1)',它在sql2005中工作,但在sql 2000中应该是'top 1'而不是'('和')'
它适用于我的解决方案。
答案 1 :(得分:5)
在.edmx文件中,您需要将Schema标记中的ProviderManifestToken更改为ProviderManifestToken =“2000”(它将是ProviderManifestToken =“2005”)
参考:Entity Framework on Sql 2000 vs. Sql 2005 and ProviderManifestToken
答案 2 :(得分:2)
某些SQL Server 2005查询包含特定于2005的特定扩展名,如ROW_NUMBER(),公用表表达式[例如WITH x AS(...)SELECT ... FROM x]等与SQL Server 2000不向后兼容。
您必须确保您的应用程序仅在SQL Server 2005上运行,或者您必须重新编写特定于SQL Server 2005的查询,以支持SQL Server 2000,2005,并且可能还需要2008年。关于不同版本的SQL Server中T-SQL语法和语义的差异,有大量文档可供使用。
我担心在没有透露实际查询文本的情况下,您不会从任何人那里得到更具体的帮助。就像我要求你纠正我的第三年英文学期论文第12行的拼写错误一样。不,你不能拥有它,但你可以为我校对吗?
答案 3 :(得分:1)
很难知道你的查询是什么样的。这个特殊的异常使我有了SELECT TOP表达式。在SQL 2005+中,一个简单的SELECT TOP可能如下所示:
SELECT TOP (50) FROM Events
但是,您将收到SQL 2000中所说的确切语法错误异常,因为SQL 2000不允许在SELECT TOP表达式中使用括号。换句话说,它需要看起来像这样:
SELECT TOP 50 FROM Events
尝试深入研究的另一个技巧是获取生成的确切SQL语句,然后进入SQL 2000企业管理器并运行它。当它在某些情况下给你相同的错误时,EM会指出你更接近语法问题的位置(尝试将你的查询分成多行)
答案 4 :(得分:1)
我在使用.NET Framework 4上运行的Windows服务中使用Entity Framework和SQL Server 2008时发生了这个错误。
这很简单,仔细检查您的查询在linq中是否类型安全。如果fld > 0
是fld
,IE不会执行varchar
之类的where子句,您应该执行fld isnot nothing
。我认为问题是当.net尝试将linq类型与db字段类型匹配时,SQL Server不喜欢运行生成的SQL。
所以基本上这个错误是野餐而不是软件故障。
我的查询是splat
qry = qry.Where(Function(rslts) (rslts.SubscriptionEndDate <= DeadLine _
And rslts.SubscriptionCancelledByName > 0 _
And rslts.SubscriptionIsRenewalEmailSent = False))
解决问题的查询是
qry = qry.Where(Function(rslts) (rslts.SubscriptionEndDate <= DeadLine _
And rslts.SubscriptionCancelledByName IsNot Nothing _
And rslts.SubscriptionIsRenewalEmailSent = False))
希望这有帮助
答案 5 :(得分:0)
听起来你很可能尝试使用SQL 2005所拥有的东西而SQL 2000却没有。公用表表达式?
答案 6 :(得分:0)
可能是LINQ。这不是100%compatible with Sql 2000。
答案 7 :(得分:0)
我没找到真正的原因。但它似乎与linq和sql2000有关,就像Charles Conway所说的那样。
以下代码适用于我:
取代:
//...
Interests original = (from m in _db.InterestsSet where m.Id == interestsToDelete.Id select m).FirstOrDefault();
//...
为:
//..
Interests original = null;
foreach (var i in from m in _db.InterestsSet where m.Id == interestsToDelete.Id select m){
original = i;
break;
}
//...
我不喜欢它,但有效...