Uploaded image for project: 'NHibernate'
  1. NHibernate
  2. NH-2133

Incorrect number of command parameters

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.2.GA
    • Fix Version/s: 3.0.0.Alpha2
    • Component/s: Core
    • Labels:
      None

      Description

      Exception: System.Data.SqlClient.SqlException: Must declare the scalar variable "@p3".

      Exception appears during select with paging when we using Projections with parameters in ordering

      run the test below from CriteriaQueryTest fixture:

      Test
      public void IncorrectNumberOfCommandParametersTest()

      { ISession session = OpenSession(); ITransaction t = session.BeginTransaction(); Course courseA = new Course(); courseA.CourseCode = "HIB-A"; courseA.Description = "Hibernate Training A"; session.Save(courseA); Student gavin = new Student(); gavin.Name = "Gavin King"; gavin.StudentNumber = 232; gavin.PreferredCourse = courseA; session.Save(gavin); Student leonardo = new Student(); leonardo.Name = "Leonardo Quijano"; leonardo.StudentNumber = 233; leonardo.PreferredCourse = courseA; session.Save(leonardo); Student johnDoe = new Student(); johnDoe.Name = "John Doe"; johnDoe.StudentNumber = 235; johnDoe.PreferredCourse = null; session.Save(johnDoe); IProjection conditional = Projections.Conditional(Restrictions.Eq("Name", "Gavin King"), Projections.Constant("Eq Name"), Projections.Constant("AnotherName")); ICriteria criteria = session.CreateCriteria(typeof(Student)); criteria.SetMaxResults(1); criteria.SetFirstResult(1); IList result = criteria.SetProjection(Projections.Alias(conditional, "CheckName")) .AddOrder(Order.Asc("CheckName")) .List(); session.Delete(gavin); session.Delete(leonardo); session.Delete(johnDoe); session.Delete(courseA); t.Commit(); session.Close(); }

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            serilla Julian Maughan added a comment -

            Thanks for the Test, Pavel. I found that the dialect was losing positional parameter information when manipulating the query for paging (MsSql2005Dialect.GetLimitString). This caused a mismatch between the number of parameters in the query, and the number of parameter values. Committed to trunk (rev. 5157)

            Show
            serilla Julian Maughan added a comment - Thanks for the Test, Pavel. I found that the dialect was losing positional parameter information when manipulating the query for paging (MsSql2005Dialect.GetLimitString). This caused a mismatch between the number of parameters in the query, and the number of parameter values. Committed to trunk (rev. 5157)

              People

              • Assignee:
                Unassigned
                Reporter:
                rembel Pavel Yaroshik
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Who's Looking?