简体   繁体   English

混淆的过程或函数有太多参数

[英]Confused Procedure or Function Has Too Many Arguments

Ok, first let me apologize for asking what seems like a redundant question.好的,首先让我为问一个看似多余的问题而道歉。 I'm attempting to optimize a stored procedure as well as the code that utilizes it.我正在尝试优化存储过程以及使用它的代码。 I've taken all parameters from both the code as well as the stored procedure and put them side-by-side in Excel to get a count of how many were in each.我已经从代码和存储过程中获取了所有参数,并将它们并排放置在 Excel 中,以计算每个参数中有多少。 There are 23 in both.两者都有 23 个。 There is 1 single output parameter which I think may be causing the issue.我认为有 1 个单个输出参数可能会导致问题。 I'm not sure how to work with that though if it is.如果是这样,我不确定如何处理它。

When I run the code I get the error当我运行代码时出现错误

System.Data.SqlClient.SqlException: Procedure or function spr_SelectClaims has too many arguments specified. System.Data.SqlClient.SqlException: 过程或函数 spr_SelectClaims 指定的参数过多。

Stored procedure parameters:存储过程参数:

@BID int = NULL,
@IndID int = NULL,
@RecDateStart datetime = NULL,
@RecDateEnd datetime = NULL,
@ServiceTypeID int = NULL,
@Billed bit = NULL,
@Paid bit = NULL,
@Approved bit = NULL,
@Void bit = 0,
@LocationID int = NULL,
@BillingAgingDate datetime = NULL,
@PaymentAgingDate datetime = NULL,
@ClaimID int = NULL,
@Eligible bit = NULL,
@BillingTypeID int = NULL,
@ClaimDetailID int = NULL,
@SortExpression varchar(25) = NULL,
@ProvidedBy int = NULL,
@Billable varchar(10) = NULL,
@ExpenseOnly varchar(10) = NULL,
@PageIndex INT = NULL,
@PageSize INT = NULL,
@RecordCount INT OUTPUT

VB.NET CODE VB.NET 代码

Dim helper As New DataBaseHelper(StoredProcedureName)

        Dim _param As SqlParameter() = {
                                           New SqlParameter("@RecordCount",SqlDbType.Int),
                                           New SqlParameter("@BID", IIf(Me.BID Is Nothing, DBNull.Value, Me.BID)),
                                           New SqlParameter("@IndID", IIf(Me.IndID Is Nothing, DBNull.Value, Me.IndID)),
                                           New SqlParameter("@RecDateStart", IIf(Me.RecDate Is Nothing, DBNull.Value, Me.RecDate)),
                                           New SqlParameter("@RecDateEnd", IIf(Me.RecDateEnd Is Nothing, DBNull.Value, Me.RecDateEnd)),
                                           New SqlParameter("@ServiceTypeID", IIf(Me.ServiceTypeID Is Nothing, DBNull.Value, Me.ServiceTypeID)),
                                           New SqlParameter("@Billed", IIf(Me.Billed Is Nothing, DBNull.Value, Me.Billed)),
                                           New SqlParameter("@Paid", IIf(Me.Paid Is Nothing, DBNull.Value, Me.Paid)),
                                           New SqlParameter("@Approved", IIf(Me.Approved Is Nothing, DBNull.Value, Me.Approved)),
                                           New SqlParameter("@Void", IIf(Me.Void Is Nothing, DBNull.Value, Me.Void)),
                                           New SqlParameter("@LocationID", IIf(Me.LocationID Is Nothing, DBNull.Value, Me.LocationID)),
                                           New SqlParameter("@BillingAgingDate", IIf(Me.BillingAgingDate Is Nothing, DBNull.Value, Me.BillingAgingDate)),
                                           New SqlParameter("@PaymentAgingDate", IIf(Me.PaymentAgingDate Is Nothing, DBNull.Value, Me.PaymentAgingDate)),
                                           New SqlParameter("@Eligible", IIf(Me.Eligible Is Nothing, DBNull.Value, Me.Eligible)),
                                           New SqlParameter("@BillingTypeID", IIf(Me.BillingTypeID Is Nothing, DBNull.Value, Me.BillingTypeID)),
                                           New SqlParameter("@ClaimID", IIf(Me.ClaimID Is Nothing, DBNull.Value, Me.ClaimID)),
                                           New SqlParameter("@ClaimDetailID", IIf(Me.ClaimDetailID Is Nothing, DBNull.Value, Me.ClaimDetailID)),
                                           New SqlParameter("@SortExpression", IIf(sortExpresion Is Nothing, DBNull.Value, sortExpresion)),
                                           New SqlParameter("@ProvidedBy", IIf(Me.ProvidedBy Is Nothing, DBNull.Value, Me.ProvidedBy)),
                                           New SqlParameter("@Billable", IIf(billableonly Is Nothing, DBNull.Value, billableonly)),
                                           New SqlParameter("@ExpenseOnly", IIf(expenseonly Is Nothing, DBNull.Value, expenseonly)),
                                           New SqlParameter("@PageIndex", Me.PageIndex),
                                           New SqlParameter("@PageSize", Me.PageSize)}
                                           _param(0).Direction =ParameterDirection.Output
        Dim dr As IDataReader = helper.RunDataReader(_param)

Excecute Code执行代码

Public Function RunDataReader(ByVal parameters As SqlParameter()) As IDataReader
    Dim dr As IDataReader
    Dim sqlCommand As String = MyBase.StoredProcedureName
    Dim dbCommand As DbCommand = db.GetStoredProcCommand(sqlCommand)
    dbCommand.CommandTimeout = 160
    If Not (parameters Is Nothing) Then
        For Each param As SqlParameter In parameters
            db.AddInParameter(dbCommand, param.ParameterName, param.DbType, param.Value)
        Next param
    End If
    'HttpContext.Current.Response.Write(parameters.Length)

    dr = db.ExecuteReader(dbCommand)
    Return dr
End Function

Ok, after doing some additional digging, I found out that for some reason those 23 parameters ended up being 92 parameters.好的,在进行了一些额外的挖掘之后,我发现由于某种原因,这 23 个参数最终变成了 92 个参数。 So, the resolution for this would probably be to figure out why the the parameters are trying to be put in 6 times.因此,解决此问题的方法可能是弄清楚为什么要尝试将参数输入 6 次。 There is a loop that's happening 6 times, and I know what that loop is Thanks to jmcilhinney suggesting to put a break point at the ExecuteReader.有一个循环发生了 6 次,我知道那个循环是什么多亏 jmcilhinney 建议在 ExecuteReader 上放置一个断点。 I was able to see a stored procedure being called 6 times.我能够看到一个存储过程被调用了 6 次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM