微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 在没有用户包装器proc的情况下从客户端应用程序执行系统存储过程(sys.sp_helptext)

我想创建一个C#方法,它接受一个参数,即存储过程的名称.然后,该方法将直接执行以下系统存储过程,而无需使用用户定义的子例程来包装此调用.

sys.sp_helptext 'proc name'

我收到错误

Could not find stored procedure ‘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]);;   
    }
}

解决方法

没问题,只是命名错了

尝试

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

代替

sqlCommand sqlCommand = new sqlCommand("sys.sp_help_text",sqlConnection);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐