开发者

Too many parameters in MVC2 Controllers or IIS problem?

I'm using a controller to call a stored procedure that requires 12 parameters. This works perfectly in debug mode locally (working against a remote database), but not when I publish it to my IIS 7 server. It complains about parameter #7, claiming it's not supplied with the URL.

The URL call looks like this;

http://localhost:50160/GetPlaces?p1=1&p2=1&p3=1&p4=1&p5=1&p6=1&p7=1&p8=1&p9=1&p10=1&p11=1&p12=1

Does anyone have any idea what may be the cause of this? Any help would be开发者_如何学运维 very appreciated here.

using System;
using System.Configuration;
using System.Web.Mvc;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Prototype.Models;

namespace Prototype.Controllers
{
    public class NameOfStoredProcedureController : Controller
    {

        char[] lastComma = { ',' };

        StringBuilder json = new StringBuilder();

        private String strCon = ConfigurationManager.ConnectionStrings["SomeConnectionString"].ConnectionString;
        private SqlConnection con;

        public StoredProcedureController()
        {
            con = new SqlConnection(strCon);
        }

        public string do_NameOfStoredProcedure(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9, int p10, int p11, int p12)
        {
            con.Open();

            using (SqlCommand cmd = new SqlCommand("NameOfStoredProcedure", con))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@parameter1", p1);
                cmd.Parameters.AddWithValue("@parameter2", p2);
                cmd.Parameters.AddWithValue("@parameter3", p3);
                cmd.Parameters.AddWithValue("@parameter4", p4);
                cmd.Parameters.AddWithValue("@parameter5", p5);
                cmd.Parameters.AddWithValue("@parameter6", p6);
                cmd.Parameters.AddWithValue("@parameter7", p7);
                cmd.Parameters.AddWithValue("@parameter8", p8);
                cmd.Parameters.AddWithValue("@parameter9", p9);
                cmd.Parameters.AddWithValue("@parameter10", p10);
                cmd.Parameters.AddWithValue("@parameter11", p11);
                cmd.Parameters.AddWithValue("@parameter12", p12);


                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        json.AppendFormat("[{0},\"{1}\"],", reader["column1"], reader["column2"]);
                    }
                }
                con.Close();
            }

            if (json.Length.ToString().Equals("0"))
            {
                return "[]";
            }

            else
            {
                return "[" + json.ToString().TrimEnd(lastComma) + "]";
            }
        }


        //http://host.com/NameOfStoredProcedure?parameter=value
        public ActionResult Index(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9, int p10, int p11, int p12)
        {
            return new ContentResult
            {
                ContentType = "application/json",
                Content = do_NameOfStoredProcedure(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12)
            };
        }
    }
}


Have you checked with "GET request length limit"?


The code has lots of issues, but none that should be stopping it.

You need to debug.

  1. Put a break point at the start of your controller and check the values of its parameters are being set as expected.

  2. Run SQL Profiler to see what calls are being made to your database, and check it is as you expect.


Set the MaxRequestBytes in http parameters to 64kb

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜