David DeWinter

Just another WordPress site

Main menu

Skip to primary content
Skip to secondary content
  • Home
  • About Me
  • Contact
  • Sample Page

Monthly Archives: November 2008

Getting Return Metadata from Stored Procedures

Posted on November 9, 2008 by David DeWinter
2

As many of you (should) know, you can select result sets from stored procedures to return them to your application, but there is no built-in metadata that tells you the specifications of the columns in each result set. However, I was always intrigued by the way the LINQ to SQL designer managed to determine, without flaw, the names, data types, etc. of the columns returned by stored procedures.

So to satisfy my curiosity I set up a trace using the SQL Server profiler against the database on my box and played with the LINQ to SQL designer to get it to find that metadata. Much to my surprise, it calls the stored procedure directly, passing NULL for each of its parameters.

Wait a minute; my stored procedure does validation, so it will raise an error when xyz parameter is NULL. I then noticed earlier in the trace a strange statement that involved the SET FMTONLY statement. Searching for that statement revealed this gem.

"Returns only metadata to the client. Can be used to test the format of the response without actually running the query."

Running something like this would then yield the metadata of the result set(s), regardless of whether errors are raised.

SET FMTONLY ON;

EXEC dbo.MyTestSproc @param1 = NULL, @param2 = NULL, @param3 = NULL

SET FMTONLY OFF;

The nice thing is that you can do this for any query, not just stored procedure executions.

Posted in LINQ to SQL, SQL Server | Tagged FMTONLY, metadata, return, return value, SET FMTONLY, Sproc, SQL Server, Stored Procedure | 2 Replies

Archives

  • November 2010
  • August 2010
  • April 2010
  • March 2010
  • January 2010
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • January 2009
  • December 2008
  • November 2008
  • September 2008
  • August 2008
  • July 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • May 2007
  • January 2007
  • October 2006
  • September 2006
  • May 2006

Meta

  • Log in
Proudly powered by WordPress