Executing a system stored procedure (sys.sp_helptext) from a client application without wrapping the user proc

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]);; } } 
+4
source share
2 answers

no problem just named wrong

to try

 SqlCommand sqlCommand = new SqlCommand("sys.sp_helptext", sqlConnection); 

instead

 SqlCommand sqlCommand = new SqlCommand("sys.sp_help_text", sqlConnection); 
+2
source

you should probably connect to the database with a username with a few more privileges. try running this sp from the management studio after logging into the same account that your application uses.

0
source

All Articles