简体   繁体   中英

C# OdbcDataReader storedproc call with params returns no data

I think there is something trivial that I am overlooking where with this issue, I am calling a stored proc, I know the call is made as I can see it in profiler, and when I run the stored proc from query analyzer it does return records as intended. Problem is when I call it from C# code, execution is happening but no results are retrieved.

What my debugging has revealed that if I have a code such as if OBJECT_ID ('tempdb..##base') IS NOT NULL drop table ##base in the stored procedure, it would not return any data using OdbcDataReader, otherwise it would return data, Can some one tell me why this is?

Thanks

Please keep in mind that the results returned to .NET are those of the LAST statement that issued a SELECT in the procedure. If the OBJECT_ID query is AFTER the SELECT statement you want returning data then you're probably not going to get results.

However, I would need to see your stored procedures to tell you for sure.

SET QUOTED_IDENTIFIER ON 
GO

SET ANSI_NULLS ON 
GO

ALTER         PROCEDURE dbo.proc_myStoredProc
AS

if OBJECT_ID ('tempdb..##base') IS NOT NULL drop table ##base
SELECT * FROM mytable
GO

SET QUOTED_IDENTIFIER OFF 
GO

SET ANSI_NULLS ON 
GO

If I remove the drop table statement above I get the data otherwise no

HOW TO CHECK FOR AND DROP A TEMP TABLE

http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM