MVC 4.0 . net应用程序和在IIS上部署后从数据库返回的值
本文关键字:部署 数据库 返回 IIS net 应用程序 MVC | 更新日期: 2023-09-27 18:04:27
这是我的第一个帖子,所以我很抱歉,如果我做错了什么。当我从Visual Studio 2012运行这个应用程序时,我的应用程序工作完美,但在IIS上部署后,从数据库返回的双值存在问题。所有的双精度值都等于0。我不知道我做错了什么。我使用强类型视图和存储过程从数据库返回值到应用程序。你知道吗?
致以最亲切的问候!
——编辑——
视图@foreach (var obj in Model.c2List)
{
<tr>
<td class="first-column">@obj.entityName</td>
<td>@obj.cet1CapitalRatio</td>
<td>@obj.surplusDeficitOfCet1Capital</td>
<td>@obj.t1CapitalRatio</td>
<td>@obj.surplusDeficitOfT1Capital</td>
<td>@obj.TotalCapitalRatio</td>
<td>@obj.SurplusDeficitOfTotalCapital</td>
</tr>
}
控制器public ActionResult TableViewParam()
{
PostedEntities postedEntities = Session["PostedEntities"] as PostedEntities;
TableC3Model obj = new TableC3Model();
return View("TableView", obj.getTableToView(postedEntities));
}
模型public List<TableC3Entity> c2List {get;set;}
public TableC3Model getTableToView(PostedEntities postedEntities)
{
TableC3Model objModel = new TableC3Model();
List<TableC3Entity> list = new List<TableC3Entity>();
DataTable dt = new DataTable();
dt = assignToDataTable(postedEntities);
using (SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["DWH"].ToString()))
{
try
{
conn.Open();
}
catch
{
throw new Exception("Blad rozpoczecia polaczenia z baza danych");
}
using (SqlCommand cmd = new SqlCommand("dbo.sp_select_from_v_c3_param", conn))
{
using (TransactionScope ts = new TransactionScope())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
SqlParameter param = cmd.Parameters.AddWithValue("IDs", dt);
param.SqlDbType = SqlDbType.Structured;
param.TypeName = "dbo.ids";
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
TableC3Entity objEntity = new TableC3Entity();
objEntity.entityName = rdr["ENTITY"].ToString();
Double temp;
Double.TryParse(rdr["CET1_Capital_ratio"].ToString(), out temp);
objEntity.cet1CapitalRatio = temp;
Double.TryParse(rdr["Surplus(+)/Deficit(-) of CET1 capital"].ToString(), out temp);
objEntity.surplusDeficitOfCet1Capital = temp;
Double.TryParse(rdr["T1 Capital ratio"].ToString(), out temp);
objEntity.t1CapitalRatio = temp;
Double.TryParse(rdr["Surplus(+)/Deficit(-) of T1 capital"].ToString(), out temp);
objEntity.surplusDeficitOfT1Capital = temp;
Double.TryParse(rdr["Total capital ratio"].ToString(), out temp);
objEntity.TotalCapitalRatio = temp;
Double.TryParse(rdr["Surplus(+)/Deficit(-) of total capital"].ToString(), out temp);
objEntity.SurplusDeficitOfTotalCapital = temp;
Double.TryParse(rdr["CET1 capital ratio including Pillar II adjustments"].ToString(), out temp);
objEntity.cet1CapitalRatioIncludingPillarIIAdjustments = temp;
Double.TryParse(rdr["Target CET1 capital ratio due to Pillar II adjustments"].ToString(), out temp);
objEntity.TargetCet1CapitalRatioDueToPillarIIAdjustments = temp;
Double.TryParse(rdr["T1 capital ratio including Pillar II adjustments"].ToString(), out temp);
objEntity.T1CapitalRatioIncludingPillarIIAdjustments = temp;
Double.TryParse(rdr["Target T1 capital ratio due to Pillar II adjustments"].ToString(), out temp);
objEntity.TargetT1CapitalRatioDueToPillarIIAdjustments = temp;
Double.TryParse(rdr["Total capital ratio including Pillar II adjustments"].ToString(), out temp);
objEntity.TotalCapitalRatioIncludingPillarIIAdjustments = temp;
Double.TryParse(rdr["Target Total capital ratio due to Pillar II adjustments"].ToString(), out temp);
objEntity.TargetTotalCapitalRatioDueToPillarIIAdjustments = temp;
list.Add(objEntity);
}
}
ts.Complete();
}
}
}
objModel.c2List = list;
return objModel;
}
实体public String entityName { get; set; }
public double cet1CapitalRatio { get; set; }
public double surplusDeficitOfCet1Capital { get; set; }
public double t1CapitalRatio { get; set; }
public double surplusDeficitOfT1Capital { get; set; }
public double TotalCapitalRatio { get; set; }
public double SurplusDeficitOfTotalCapital { get; set; }
public double cet1CapitalRatioIncludingPillarIIAdjustments { get; set; }
public double TargetCet1CapitalRatioDueToPillarIIAdjustments { get; set; }
public double T1CapitalRatioIncludingPillarIIAdjustments { get; set; }
public double TargetT1CapitalRatioDueToPillarIIAdjustments { get; set; }
public double TotalCapitalRatioIncludingPillarIIAdjustments { get; set; }
public double TargetTotalCapitalRatioDueToPillarIIAdjustments { get; set; }
在SQL Server上有一个简单的选择从视图,工作得很好
我的猜测是您与SQLServer和IIS上的文化不匹配。
SQLServer(可能)返回使用美国文化(1.23)的双精度,但您的IIS运行在不同的文化下,使用带逗号的双精度(1,23)。这将使TryParse失败并返回0。