在 IIS 上部署后从数据库返回的 MVC 4.0 .NET 应用程序和值

Posted

技术标签:

【中文标题】在 IIS 上部署后从数据库返回的 MVC 4.0 .NET 应用程序和值【英文标题】:MVC 4.0 .NET app and values returned from database after deployment on IIS 【发布时间】:2014-05-21 08:54:43 【问题描述】:

这是我的第一篇文章,如果我做错了什么,我很抱歉。 当我从 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 上,可以从 View 中进行简单的选择,效果很好。

【问题讨论】:

我建议您添加一些代码来帮助我们帮助您。 IIS 是否位于您的开发机器上? @slinzerthegod 不,IIS 位于另一台安装了 WS 2008 R2 和 .NET Framework 4.5 的机器上。 可能与文化有关。检查我的答案。 【参考方案1】:

我的猜测是您与 SQLServer 和 IIS 上的文化不匹配。

SQLServer(可能)返回使用美国文化 (1.23) 的双精度数,但您的 IIS 在不同的文化下运行,它使用带逗号的双精度数 (1,23)。这将使 TryParse 失败并返回 0。

【讨论】:

是的,它与 SQLServer 和 IIS 上的文化不匹配。非常感谢您的帮助:)保重!

以上是关于在 IIS 上部署后从数据库返回的 MVC 4.0 .NET 应用程序和值的主要内容,如果未能解决你的问题,请参考以下文章

我可以在 .NET Framework 4.0 上运行 MVC 5 应用程序吗?

ASP.NET MVC 4 + Entity Framework 6 + SQL Compact Edition 4.0 部署无需安装

处理程序“ExtensionlessUrlHandler-Integrated-4.0”在其模块列表中有一个错误模块“ManagedPipelineHandler”

ASP.NET MVC部署网站到IIS,只列出网站目录

如何使用 .Net 4.0 中包含的 HttpClient 类将文件上传到在 IIS Express 中运行的 Asp.Net MVC 4.0 操作

将站点部署到 IIS 服务器