ストアド プロシージャの名前という 1 つのパラメーターを受け入れる C# メソッドを作成したいと考えています。このメソッドは、ユーザー定義のサブ ルーチンを使用してこの呼び出しをラップすることなく、次のシステム ストアド プロシージャを直接実行します。
sys.sp_helptext 'proc name'
エラーが発生します:
ストアド プロシージャ 'sys.sp_help_text が見つかりませんでした
これは権限の問題ですか (私はテスト データベースの管理者です)、それとも資格の問題ですか?
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]);;
}
}