I would like to create a C# method that accepts one parameter, the name of a stored procedure. The method will then execute the following system stored procedure directly without using a user-defined sub routine to wrap this call.
sys.sp_helptext 'proc name'
I get the error:
Could not find stored procedure ‘sys.sp_help_text
Is this a permissions issue (I am Admin of my test db) or qualification issue?
public static string GetStoredProcedure(string objectName, string connectionString)
{
using (SqlConnection sqlConnection = new SqlConnection())
{
sqlConnection.ConnectionString = connectionString;
sqlConnection.Open();
SqlCommand sqlCommand = new SqlCommand("sys.sp_help_text", sqlConnection);
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.Parameters.AddWithValue("@objname", objectName);
DataSet ds = new DataSet();
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
sqlDataAdapter.SelectCommand = sqlCommand;
sqlDataAdapter.Fill(ds);
return DataTableToString(ds.Tables[0]);;
}
}
no issue, just named wrong
try
instead of