SharePoint Web部件-存储过程中的RAISEROR导致403

本文关键字:RAISEROR 导致 过程中 存储过程 Web 部件 存储 SharePoint | 更新日期: 2023-09-27 18:19:44

我有一个web部件,它调用SQL Server存储过程,当出现错误时,SharePoint页面应该通过标签显示错误消息。

但是,当存储过程中出现错误时,SharePoint页面显示403错误。当没有引发错误时,页面将按预期运行。

这个问题只发生在标准用户(网站访问者)身上,如果我以SharePoint管理员的身份执行此代码,一切都会很好,所以我猜这是某种权限问题。

有人能帮忙吗?谢谢

SQL代码如下所示。。。

CREATE PROCEDURE dbo.SomeProcedure
(
    @SomeValue INT
)
AS
IF EXISTS(SELECT 1 FROM dbo.SomeTable WHERE SomeColumn = @SomeValue)
BEGIN
    RAISERROR('Already completed.', 16, 1);
    RETURN;
END;
-- otherwise do something

带有C#代码,例如:

    private void UpdateSomething()
    {
        string errorMessage;
        errorMessage = DataAccess.UpdateSomeValue(strSomeValue);
        if (string.IsNullOrEmpty(errorMessage))
        {
            lblInformationMessage.Text = "Update completed successfully.";
            lblInformationMessage.Visible = true;
        }
        else
        {
            lblErrorMessage.Text = string.Concat("There was an error: ", errorMessage);
            lblErrorMessage.Visible = true;
        }
    }

这需要以下内容:

    public static string UpdateSomeValue(string strSomeValue)
    {
        string errorMessage = "";
        SqlConnection cnn;
        SqlCommand cmd = new SqlCommand();
        try
        {
            //connection
            cnn = new SqlConnection(strCnn);
            cnn.Open();
            //command
            cmd.Connection = cnn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "dbo.SomeProcedure";
            cmd.Parameters.Add(new SqlParameter("@SomeValue", SqlDbType.Int, 18));
            cmd.Parameters["@SomeValue"].Value = strSomeValue;
            cmd.ExecuteNonQuery();
            cnn.Close();
        }
        catch (SqlException ex)
        {
            errorMessage = ex.Message;
            Utility.Writelog(HttpContext.Current.Request.Url.ToString());
            Utility.Writelog(ex.Message);
        }
        finally
        {
            cmd.Dispose();
        }
        return errorMessage;
    }

SharePoint Web部件-存储过程中的RAISEROR导致403

如果它可以管理,为什么不运行它提升的

spsecurity.runwithelevatedprivileges(delegate){

errorMessage=DataAccess.UpdateSomeValue(strSomeValue);

});