好的,首先让我为询问看似多余的问题而道歉。我试图优化存储过程以及使用它的代码。我从代码和存储过程中获取了所有参数,并将它们并排放在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
答案 0 :(得分:0)
好的,经过一些额外的挖掘,我发现由于某种原因,这23个参数最终成为92个参数。因此,对此的解决方案可能是弄清楚为什么参数试图放入6次。有一个循环发生了6次,我知道循环是什么感谢jmcilhinney建议在ExecuteReader上设置一个断点。我能够看到存储过程被调用了6次。