簡體   English   中英

混淆的過程或函數有太多參數

[英]Confused Procedure or Function Has Too Many Arguments

好的,首先讓我為問一個看似多余的問題而道歉。 我正在嘗試優化存儲過程以及使用它的代碼。 我已經從代碼和存儲過程中獲取了所有參數,並將它們並排放置在 Excel 中,以計算每個參數中有多少。 兩者都有 23 個。 我認為有 1 個單個輸出參數可能會導致問題。 如果是這樣,我不確定如何處理它。

當我運行代碼時出現錯誤

System.Data.SqlClient.SqlException: 過程或函數 spr_SelectClaims 指定的參數過多。

存儲過程參數:

@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 代碼

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)

執行代碼

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

好的,在進行了一些額外的挖掘之后,我發現由於某種原因,這 23 個參數最終變成了 92 個參數。 因此,解決此問題的方法可能是弄清楚為什么要嘗試將參數輸入 6 次。 有一個循環發生了 6 次,我知道那個循環是什么多虧 jmcilhinney 建議在 ExecuteReader 上放置一個斷點。 我能夠看到一個存儲過程被調用了 6 次。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM