/* Compile from the command line with: csc /target:library helpdb.cs You may need to add C:\Windows\Microsoft.NET\Framework\v3.5 to your path. */ using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; public partial class StoredProcedures { [Microsoft.SqlServer.Server.SqlProcedure] public static void helpdb(String dbname) { // Connect through the context connection. using (SqlConnection conn = new SqlConnection("context connection=true")) { conn.Open(); // Setup the command to run sp_helpdb. SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "sp_helpdb"; cmd.Parameters.Add("@dbname", SqlDbType.NVarChar, 128); cmd.Parameters["@dbname"].Value = @dbname; // And run it. SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet dataset = new DataSet(); da.Fill(dataset); // Now set up the command to insert the data into the temp table. cmd.CommandType = CommandType.Text; cmd.Parameters.Clear(); cmd.CommandText = "INSERT #helpdb(dbname, logicalname, fileid, filename, " + " filegroup, size, maxsize, growth, usage) " + " SELECT @dbname, name, fileid, filename, " + " filegroup, size, maxsize, growth, usage " + " FROM @helpdb2"; // Set up the @dbname parameter cmd.Parameters.Add("@dbname", SqlDbType.NVarChar, 128); cmd.Parameters["@dbname"].Value = dbname; // Set up the table parameter. cmd.Parameters.Add("@helpdb2", SqlDbType.Structured); cmd.Parameters["@helpdb2"].TypeName = "dbo.helpdb_type"; cmd.Parameters["@helpdb2"].Value = dataset.Tables[1]; // Insert all rows from the data table. cmd.ExecuteNonQuery(); dataset.Dispose(); da.Dispose(); cmd.Dispose(); } } };