Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#5 ParameterMarker problem

closed-works-for-me
Bengt Gunne
None
5
2004-04-23
2004-04-14
Ulf Werner
No

Hi,

I'm using MPM 1.2.1 against MSSQLServer and using the
filter ParameterMarkers. My application is written in
ODBC style with '?' as parameter markers. If I try to use
the Sql plugin I get the exception
System.Data.SqlClient.SqlException: Must declare the
variable '@p'.

I attach a textfile with the complete errormessage.

Regards
Ulf Werner
Decerno

Discussion

  • Ulf Werner
    Ulf Werner
    2004-04-14

    Error message

     
  • Fredrik Ĺlund
    Fredrik Ĺlund
    2004-04-15

    • assigned_to: nobody --> mimerbg
     
  • Bengt Gunne
    Bengt Gunne
    2004-04-15

    Logged In: YES
    user_id=895705

    The parameter marker filter generated parameter markers
    with names p%d instead of p1, p2 and so on. Sql Server
    ignores %d (for som reason) and asks for a parameter named
    @p.

    A correction has been committed to CVS. For your application
    to work you may have to review the parameter marker names
    used in calls to MpmParameter. These should be set to p1,
    p2, p3 and so on in order to cooperate with the Sql Filter.

    Please let me know if it works for you!

    I am investigating whether parameters without the name set
    can automatically adopt the p1,p2, p3 convention.

     
  • Bengt Gunne
    Bengt Gunne
    2004-04-15

    • status: open --> pending
     
  • Bengt Gunne
    Bengt Gunne
    2004-04-16

    Logged In: YES
    user_id=895705

    It is now possible to let Mpm do the parameter naming:

    MpmParameter par1 = new MpmParameter();
    par1.MpmType = MpmType.Int;
    par1.Value = 10;
    MpmParameter par2 = new MpmParameter();
    par2.MpmType = MpmType.Int;
    par2.Value = 10;
    MpmCommand cmd = new MpmCommand("insert into t values
    (?,?)", conn);
    //
    // Par1 will now be called "p1"
    //
    cmd.Parameters.Add(par1);
    //
    // Par2 will now be called "p2"
    //
    cmd.Parameters.Add(par2);

    The above logic allows, for example, Sql Server to be used
    which wants matching parameter names in both SQL
    statement and parameters. Note that the ParameterMarkers
    SQL Filter must be used.

     
  • Ulf Werner
    Ulf Werner
    2004-04-23

    • status: pending --> open-works-for-me
     
  • Ulf Werner
    Ulf Werner
    2004-04-23

    Logged In: YES
    user_id=1021053

    Now it works!

    Thanks again
    Ulf

     
  • Bengt Gunne
    Bengt Gunne
    2004-04-23

    • status: open-works-for-me --> closed-works-for-me