Long-time lurker, first-time poster here :)
I've decided to ask here since I've grown tired of searching in Google, SO and such. I'm experiencing this error when importing a Stored Procedure from my SQL 2005 DB to my Website (FW 4.0, C#) LINQ project:
"The return types for the following stored procedures could not be detected"
I have two queries. I'd like to note that I'm not using temporary tables. These queries have only been edited in variable names and such, for security measures. Anyways, here's the one that works:
ALTER PROCEDURE [dbo].[spMyWorkingProc]
@OS numeric
AS
BEGIN
SET NOCOUNT ON;
DECLARE @sql varchar(5000)
set @sql = '
SELECT
*
FROM MYDB.dbo.MYVIEW
WHERE OS = ' + CONVERT(varchar, @OS)
EXEC('
SET NOCOUNT ON
SELECT * FROM
OPENROWSET(''SQLOLEDB'', ''MYDB''; ''user''; ''password'', ''' + @sql + ''')')
END
And here's the one which doesn't:
ALTER PROCEDURE [dbo].[spNotWorking]
@IDCLIENT int,
@PPNO char(10)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @sql varchar(5000)
set @sql = '
SELECT
*
FROM MYDB.dbo.MYOTHERVIEW
WHERE ID = ' + CONVERT(VARCHAR, @IDCLIENT) + ' AND PASSPORTNO = ' + @PPNO + ' ORDER BY AGE'
EXEC('
SET NOCOUNT ON
SELECT * FROM
OPENROWSET(''SQLOLEDB'', ''MYDB''; ''user''; ''password'', ''' + @sql + ''')')
END
Here's what I've tried and found, along with a few notes and questions:
Both users (LINQ and Remote Server) are db_owner.
The non-working stored procedure works if I leave it with only one parameter (doesn't matter which one). If I add a new one, it doesn't work.
If I make an empty SP with a simple select * from any table, and two or more parameters, it works (so it doesn't make sense).
Let's say the problem is in EXEC. If so, how come the first SP works?. Ok, the problem isn't there then. (that's what logic tells me, I guess?)
The problem is not the view, as it doesn't work if I use the view I access in the working SP.
I need to do this using the queries provided. I can't use linked servers or anything similar as we need to do this to connect to 6.5 databases, and it doesn't solve or explain why the first SP works and the second one doesn't, while using the same method.
I tried to add a parameter (taken from the non-working SP) to the working SP and it works, so it must be something with the second SP, but I dunno what :/
Okay, if I modify the 2nd SP and remove the parameters in the style of @VAR and hardcode them into a single @sql variable, it works perfectly. So, I see it must be something with including variables into a dynamic query (or something).
I'm literally pulling my hair off, so any ideas and suggestions are welcome!
Thanks in advance! - DARKGuy