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;
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)
};
}
}
}