LINQ to SQL-存储过程返回类型错误

问题描述:

在SQL 2005上,我有一个简单的SP,可以从表中选择行.SP不使用临时表或返回多个结果集.在VS2010中,我将SP从服务器资源管理器中拖动到DBML设计器中,并将该SP添加到LINQ数据上下文中.一切正常.如果随后将表和SP脚本编写到另一台活动SQL 2005服务器上,则会出现错误无法检测到以下存储过程的返回类型..",就像我说的那样,通常没有临时表或多个结果集产生此错误.服务器上是否可能有其他原因导致这种情况?

On SQL 2005 I have a simple SP that selects rows from a table. The SP does not use temporary tables or return multiple result sets. In VS2010 I drag the SP from the Server Explorer to the DBML designer and the SP is added to the LINQ data context. Everything works okay. If I then script the table and SP on to another live SQL 2005 server I am getting the error "The return types for the following stored procedures could not be detected .. " Like I say, no temp tables or multiple result sets that would typically produce this error. Could there be something else on the server causing this?

SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE PROCEDURE [dbo].[spUsers]
    AS
    BEGIN
        SET NOCOUNT ON;

        SELECT top 100 * from Users
    END

好吧,它在实时服务器上失败的原因是与访问DBMS上的元数据所需的特权有关.这些是从SP创建返回值数据类型所必需的.通过提升SQL用户帐户,然后将SP拖到DBML设计器上,..宾果游戏..就可以了!

Okay, the reason it was failing on the live server is to do with privilages needed to access the meta-data on the DBMS. These are needed to create the return value data type from the SP. By elevating the SQL user account and then dragging the SP on onto the DBML designer .. bingo .. it works!