What causes “Incorrect syntax near <stored procedure name>” in EF Code First and SQL 2005?

。_饼干妹妹 提交于 2019-12-03 12:48:16

Solution found by @Dan himself (couldn't post due to rep)

The solution I found to this issue was simply to add the keyword "EXEC" to the query:

var myEntities = dbContext.Database.SqlQuery<MyEntity>("EXEC GetDataFromMySp @EntityId = {0}", entityId);

This solution fixed the issue with SQL Server 2005 and still worked with SQL Server 2008 R2.

You only need EXEC if there are any statements before "GetDataFromMySp" in the batch. A stored procedure name by itself should be OK.

I'd run SQL Profiler to see what is being actually being sent by EF.

Things like "prepared statements" issue extra commands as part of the batch in addition to your command text.

See this: http://social.msdn.microsoft.com/Forums/eu/adonetefx/thread/bae30a3d-7a66-4aff-af99-6426cf0483b5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!