I would like to create a C # method that takes one parameter, the name of the stored procedure. Then the method will execute the following system stored procedure directly, without using a user routine to transfer this call.
sys.sp_helptext 'proc name'
I get an error message:
Could not find stored procedure 'sys.sp_help_text
Is it a permissions issue (I'm the admin of my db test) or a 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]);; } }
source share