4

ストアド プロシージャの名前という 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]);;   
    }
}     
4

2 に答える 2

2

問題ありません。名前が間違っているだけです

試す

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

それ以外の

SqlCommand sqlCommand = new SqlCommand("sys.sp_help_text", sqlConnection);
于 2012-08-18T07:43:22.970 に答える
0

おそらく、より多くの権限を持つログインでデータベースに接続する必要があります。アプリが使用しているのと同じアカウントでログインした後、managment studio からこの sp を実行してみてください。

于 2012-08-18T07:39:26.987 に答える