4

我想创建一个接受一个参数的 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

您可能必须使用具有更多权限的登录名连接到数据库。使用您的应用程序使用的相同帐户登录后,尝试从管理工作室执行此 sp。

于 2012-08-18T07:39:26.987 回答