SQL SqlException (0x80131904):第 28 行:“(”附近的语法不正确。]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1413881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SqlException (0x80131904): Line 28: Incorrect syntax near '('.]
提问by AiShiguang
Please someone help me! I have an app running on windows 2003 with sql server 2005. When I try to deploy this some app in other server on windows 2003 with sql server 2000, some pages of the app shows the message bellow:
请有人帮助我!我有一个运行在带有 sql server 2005 的 windows 2003 上的应用程序。当我尝试在带有 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
an unsing the tecnologies bellow:
下面介绍一下技术:
asp.net mvc 1
ADO.net and LINQ
asp.net mvc 1
ADO.net 和 LINQ
please help me!
请帮我!
回答by AiShiguang
open your model .edmx with xml editor, and modify this
使用 xml 编辑器打开您的模型 .edmx,并修改它
ProviderManifestToken="2008"
to
到
ProviderManifestToken="2000"
it might be the linq .first() that generates the sql script 'Top (1)' which works in sql2005, but should be 'top 1' with out '('and ')' in sql 2000
可能是 linq .first() 生成了在 sql2005 中工作的 sql 脚本 'Top (1)',但在 sql 2000 中应该是'top 1',没有'('and ')'
it works in my solution.
它适用于我的解决方案。
回答by Richard Harrison
In the .edmx file you need to change the ProviderManifestToken to 2000 in the Schema tag to ProviderManifestToken="2000" (it will be ProviderManifestToken="2005")
在 .edmx 文件中,您需要将 Schema 标记中的 ProviderManifestToken 更改为 2000 为 ProviderManifestToken="2000"(它将是 ProviderManifestToken="2005")
ref: Entity Framework on Sql 2000 vs. Sql 2005 and ProviderManifestToken
回答by Richard Harrison
Some SQL Server 2005 queries which contain 2005-specific extensions like ROW_NUMBER(), common table expressions [e.g. WITH x AS (...) SELECT ... FROM x], etc. are not backwards compatible with SQL Server 2000.
某些 SQL Server 2005 查询包含 2005 特定的扩展,如 ROW_NUMBER()、公共表表达式 [例如 WITH x AS (...) SELECT ... FROM x] 等,与 SQL Server 2000 不向后兼容。
You must either ensure that your application runs only on SQL Server 2005 or you must rework your queries that are specific to SQL Server 2005 to support SQL Server 2000, 2005, and probably 2008 too for good measure. There is plenty of documentation available as to what the differences are in T-SQL syntax and semantics among the different versions of SQL Server.
您必须确保您的应用程序仅在 SQL Server 2005 上运行,或者您必须重新编写特定于 SQL Server 2005 的查询,以支持 SQL Server 2000、2005 和 2008,以便更好地衡量。关于不同版本的 SQL Server 之间 T-SQL 语法和语义的差异,有大量文档可用。
I'm afraid you're not going to get much more specific help from anyone without revealing the actual query text. That would be like me asking you to correct my spelling error on line 12 of my 3rd year English term paper. No, you can't have it, but can you proofread it for me?
恐怕您不会在不透露实际查询文本的情况下从任何人那里获得更具体的帮助。这就像我要求你更正我三年级英语学期论文第 12 行的拼写错误。不,你不能拥有它,但你能帮我校对它吗?
回答by Steve Flook
It is quite difficult w/o having an idea of what your query looks like. This particular exception has got me before with SELECT TOP expressions. In SQL 2005+ a simple SELECT TOP could look like this:
如果不知道您的查询是什么样的,这是非常困难的。这个特殊的例外让我之前使用 SELECT TOP 表达式。在 SQL 2005+ 中,一个简单的 SELECT TOP 可能如下所示:
SELECT TOP (50) FROM Events
However you will receive the exact syntax error exception you are speaking of in SQL 2000 because SQL 2000 doesn't allow parenthesis in the SELECT TOP expression. In other words it needs to look like this:
但是,您将收到您在 SQL 2000 中所说的确切语法错误异常,因为 SQL 2000 不允许在 SELECT TOP 表达式中使用括号。换句话说,它需要看起来像这样:
SELECT TOP 50 FROM Events
Another tip to try and get to the bottom of this is to get the exact SQL statement generated, then go into SQL 2000 Enterprise Manager and run it. When it gives you the same error in some cases EM will point you a little closer as to where the syntax issue exists (try splitting your query up on multiple lines)
另一个尝试深入了解此问题的技巧是获取生成的确切 SQL 语句,然后进入 SQL 2000 企业管理器并运行它。当它在某些情况下给你同样的错误时,EM 会指向你更接近语法问题的位置(尝试将你的查询拆分成多行)
回答by Andre
This error just happened to me using Entity Framework with SQL Server 2008 in a Windows service running on .NET framework 4.
这个错误刚刚发生在我在 .NET framework 4 上运行的 Windows 服务中使用 Entity Framework 和 SQL Server 2008。
It was simple really, double check your query is type safe in linq. IE don't do a where clause like fld > 0
if the fld
is a varchar
, you should do where fld isnot nothing
. The problem I think is when .net tries to match up the linq types to the db field types and SQL Server doesn't like running the SQL generated.
这真的很简单,仔细检查您的查询在 linq 中是否类型安全。IE 不做 where 子句,比如fld > 0
if the fld
is a varchar
,你应该做 where fld isnot nothing
。我认为的问题是当 .net 尝试将 linq 类型与 db 字段类型匹配时,SQL Server 不喜欢运行生成的 SQL。
So basically this error is a picnic not a software glitch.
所以基本上这个错误是野餐而不是软件故障。
My query that went splat was
我的查询是 splat 是
qry = qry.Where(Function(rslts) (rslts.SubscriptionEndDate <= DeadLine _
And rslts.SubscriptionCancelledByName > 0 _
And rslts.SubscriptionIsRenewalEmailSent = False))
The query that solved the problem was
解决问题的查询是
qry = qry.Where(Function(rslts) (rslts.SubscriptionEndDate <= DeadLine _
And rslts.SubscriptionCancelledByName IsNot Nothing _
And rslts.SubscriptionIsRenewalEmailSent = False))
Hope this helps
希望这可以帮助
回答by Andre
I did'nt find the real reason. But it seems to be something about the linq and sql2000, exactly as Charles Conway said.
我没有找到真正的原因。但这似乎是关于 linq 和 sql2000 的,正如 Charles Conway 所说。
The code below works for me:
下面的代码对我有用:
replace:
代替:
//...
Interests original = (from m in _db.InterestsSet where m.Id == interestsToDelete.Id select m).FirstOrDefault();
//...
to:
到:
//..
Interests original = null;
foreach (var i in from m in _db.InterestsSet where m.Id == interestsToDelete.Id select m){
original = i;
break;
}
//...
I don't like it, but works...
我不喜欢它,但有效...
回答by MartW
It sounds quite possible you're trying to use something that SQL 2005 has and SQL 2000 doesn't. Common table expressions?
听起来很可能您正在尝试使用 SQL 2005 具有而 SQL 2000 没有的东西。常用表表达式?
回答by Chuck Conway
It could be LINQ. It's not 100% compatible with Sql 2000.
它可能是 LINQ。它不是 100%兼容 Sql 2000。