SSRS DateTime参数DefaultValue格式

时间:2015-03-23 01:51:24

标签: c# asp.net datetime reporting-services

我有一个asp.net应用程序,允许用户为SSRS报告创建订阅。

我的所有报告都有@StartDate和@EndDate参数,默认值为

=Today.AddDays(-14) 

=Today 

分别

我的c#代码在加载订阅表单时检查参数的defaultvalue,以预先填充AspxDateEdit控件。这一切都适用于我的开发环境(新西兰)。

        ItemParameter[] Parameters = _Rs.GetItemParameters(_ThisReportPath, null, true, null, null);
        if (Parameters.Any())
        {
            foreach (ItemParameter Rp in Parameters)
            {
                if (Rp.ParameterTypeName == "DateTime" && Rp.PromptUser)
                {
                    var MyDtControl = new ASPxDateEdit
                    {
                        ID = "dtParam" + MyTable.Rows.Count
                    };
                    DateTime MyFormattedDisplayDate = Convert.ToDateTime(Rp.DefaultValues[0], CultureInfo.CurrentCulture.DateTimeFormat);
                    MyDtControl.Date = MyFormattedDisplayDate.Date;
                }
            }
        }

最初的网站将驻留在澳大利亚的服务器上,随后推广到世界各地,因此我需要保持DateTimes的格式动态(特定于文化)。

在实时系统上加载报表的订阅表单时,我收到错误“字符串未被识别为有效的DateTime。”转储Parameter.DefaultValues [0]的值显示AU服务器上的默认值是美国形式( MM / dd / yyyy )导致错误。记录代码:

SQLReportsLogic.Log(MyLog, "(Line 599 - LoadParams)Default Param Value:" + Rp.DefaultValues[0] + "/ ServerDateFormatToday:" + DateTime.Now);

结果输出:

(Line 599 - LoadParams)Default Param Value:3/24/2015 12:00:00 AM/ ServerDateFormatToday:24/03/2015 7:14:47 AM

预计格式将与服务器的文化信息保持一致,即 dd / MM / yyyy

-   The report language is set to User!Language
-   The Server System Locale is English(Australia)
-   The Server Location is Australia
-   The Server Datetime format is set to ShortDate=d/MM/yyyy LongDate=dddd, d MMMM yyyy
-   The Server Language is set to English (Australia)
-   The Reporting Services Service is running under Local System Account
-   WWW is running under Local System Account
-   SSRS is running in Native Mode

SSRS在确定= Today()的格式时具体从何处获取DateTime格式?据我所知,到目前为止,我应该在系统指定格式dd / MM / yyyy中生成= Today() 我也尝试将参数的DefaultValue格式化为

-   “yyyy/MM/dd hh:mm:ss” = The DefaultValue expression for the report parameter ‘StartDate’ contains an error: Input string was not in a correct format
-   “yyyy/MM/dd hh:mm” = The DefaultValue expression for the report parameter ‘StartDate’ contains an error: Input string was not in a correct format
-   “yyyy/MM/dd” = The DefaultValue expression for the report parameter ‘StartDate’ contains an error: Input string was not in a correct format
-   DateFormat.ShortDate = The property ‘DefaultValue’ of report parameter ‘StartDate’ doesn’t have the expected type.
-   DateFormat.LongDate = The property ‘DefaultValue’ of report parameter ‘StartDate’ doesn’t have the expected type.
-   DateFormat.GeneralDate = The property ‘DefaultValue’ of report parameter ‘StartDate’ doesn’t have the expected type.

除非我能解决SSRS呈现= Today()的方式,否则我的双手将被绑定。据我了解,我需要使用错误的文化找到SSRS安装的问题?它是在某个地方的注册表中查找的吗?

我正在使用VS2012(11.0.61030.00 Update 4)和SSDTBI插件(MSSQL Server Reporting Services Designers版本11.0.3436.0)

1 个答案:

答案 0 :(得分:0)

最后找到了正确的搜索术语,并在两天后找到了解决方案 - 如本文所述覆盖SSRS GetWebRequest。 https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f147c641-d5c2-49e8-97f6-b654bec8366d/datetime-format-for-webservice-api-calls?forum=sqlreportingservices#0c223835-dd5c-4471-b736-1d9dad014144

public partial class ReportingService : DevReportService.ReportingService2010
{

    /// <summary>

    /// Gets or sets the culture that is used when generating the report.

    /// </summary>

    /// <value>The culture that is used when generating the report.</value>

    public CultureInfo Culture { get; set; }

    protected override WebRequest GetWebRequest(Uri uri)
    {

        WebRequest request = base.GetWebRequest(uri);

        CultureInfo culture = this.Culture ?? CultureInfo.CurrentCulture;

        request.Headers.Add(HttpRequestHeader.AcceptLanguage, culture.Name);

        return request;

    }

}