PetaPoco存储过程错误“关键字”FROM“附近的错误语法”} [英] PetaPoco stored procedure error "Incorrect syntax near the keyword 'FROM'."}
问题描述
我正在尝试使用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错误。
起初我正在使用带有参数的存储过程,而@字符引起了一个问题,一旦用@@修复,我开始收到这个错误,所以我用一个简单的选择声明。该过程在Management Studio中执行完全正常。
使用PetaPoco与select语句是很好的,数据被映射到动态或对象模型完全正常。我创建了一个垃圾SQL字符串,并返回相同的错误,这是我从中获取通用错误的想法。
这是我正在使用的选择工作正常
var dynTest =
db.Query< dynamic>(
SELECT TOP 10 * FROM [BI]。[dbo]。[Managers] ORDER BY [ConsecutiveDays] desc);
它试图在其前面附加select子句。
如果你放一个;在您的查询开始时,不会尝试附加它。
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");
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存储过程错误“关键字”FROM“附近的错误语法”}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!