Mark Brown's Blog

TFS, Visual Studio, SQL Server, BizTalk, SharePoint, .Net, and more ...

How to determine schema definitions of Stored Procedures in .Net

 Here is some code to get an idea.  Note that if a stored procedure sends back a temp table this does not work.   If anyone has a way to do temp table schemas I would like to know.

 class Program
{

static void Main(string[] args)
{
string connectionString = GetConnectionString();
using (SqlConnection connection = new SqlConnection(connectionString))
{
// Connect to the database then retrieve the schema information.
connection.Open();
DataTable table = connection.GetSchema("Procedures");
// Display the contents of the table.
DisplayData(table);
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
}
}

private static string GetConnectionString()
{
// To avoid storing the connection string in your code,
// you can retrieve it from a configuration file.
return "Data Source=<servername>;Database=<database>;Integrated Security=SSPI;";
}

private static void DisplayData(System.Data.DataTable table)
{
  foreach (System.Data.DataRow row in table.Rows)
  {
    foreach (System.Data.DataColumn col in table.Columns)
    {
      Console.WriteLine("{0} = {1}", col.ColumnName, row[col]);
    }
    Console.WriteLine("============================");
  }
}

Published Tuesday, March 06, 2007 2:59 PM by mab
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

March 6, 2007 11:40 PM

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required
Submit

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker