PetaPoco 存储过程错误“关键字“FROM”附近的语法不正确。”}
我将 C# 与 TSQL 和 SQL Server 2005 一起使用,
我尝试使用 PetaPoco 将数据集作为对象列表返回。这是我刚才使用的代码,
var s = PetaPoco.Sql.Builder.Append("USE [BI] EXEC [dbo].[TestProcedure2];");
var result = db.Query<dynamic>(s);
var result2 = db.Query<dynamic>("USE [BI] EXEC [dbo].[TestProcedure2];");
我认为错误消息是 petaPoco 失败时的通用 sql 错误。
起初,我使用带有参数的存储过程,@字符导致了问题,一旦用@@修复了这个问题,我就开始收到此错误,所以我用一个简单的 select 语句创建了一个存储过程。该过程在 Management Studio 中执行得非常好。
将 PetaPoco 与 select 语句一起使用就很好,并且数据可以完全映射到动态模型或对象模型。我创建了一个垃圾 SQL 字符串,它返回了相同的错误,这就是我从中得到通用错误想法的地方。
这是我正在使用的选择,效果很好
var dynTest =
db.Query<dynamic>(
"SELECT TOP 10 * FROM [BI].[dbo].[Managers] ORDER BY [ConsecutiveDays] desc");
I'm using C# with TSQL and SQL Server 2005
I'm trying to use PetaPoco to return a dataset as a list of objects. this is the code I'm using just now
var s = PetaPoco.Sql.Builder.Append("USE [BI] EXEC [dbo].[TestProcedure2];");
var result = db.Query<dynamic>(s);
var result2 = db.Query<dynamic>("USE [BI] EXEC [dbo].[TestProcedure2];");
I think the error message is a generic sql error for when petaPoco fails.
At first I was using a stored procedure with paramaters and the @ character was causing a problem, once that was fixed with @@ i started getting this error so I made a stored procedure with a simple select statement. The procedure executes completely fine in Management Studio.
Using PetaPoco with select statements is fine and the data is mapped both to a dynamic or an object model completely fine. I created a garbage SQL string and it returned the same error which is where I'm getting the generic error idea from.
This is the select I'm using which works fine
var dynTest =
db.Query<dynamic>(
"SELECT TOP 10 * FROM [BI].[dbo].[Managers] ORDER BY [ConsecutiveDays] desc");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它试图在其前面附加 select 子句。
如果你加了一个“;”在查询开始时,它不会尝试附加它。
Its trying to append the select clause in front of it.
If you put a ";" at the start of your query it won't try to append it.
PetaPoco 假设您想要执行 SELECT,并且如果您不包含 SELECT,则会推断出一个。
为了避免执行自动 SELECT,您应该
在查询之前使用:
PetaPoco assumes that you want to perform a SELECT and will infer one if you don't include one.
To avoid doing the automatic SELECT you should use:
Prior to your query.