SSRS 日期时间参数默认值格式
SSRS DateTime Parameters DefaultValue Format
我有一个 asp.net 应用程序,允许用户为 SSRS 报告创建订阅。
我所有的报告都有@StartDate 和@EndDate 参数,它们的默认值为
=Today.AddDays(-14)
和
=Today
分别。
我的 C# 代码在加载订阅表单时检查参数的默认值,以预填充 AspxDateEdit 控件。这在我的开发环境 (NZ) 上一切正常。
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 的格式动态(特定于文化)。
在实时系统上加载报告的订阅表单时,我收到错误消息“字符串未被识别为有效的日期时间。”转储 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() 的格式时具体从哪里获取日期时间格式?据我了解我迄今为止的研究,这应该以 dd/MM/yyyy 的系统分配格式生成 =Today()
我还尝试将参数的默认值格式化为
- “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 更新 4)和 SSDTBI 插件(MSSQL Server Reporting Services 设计器版本 11.0.3436.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;
}
}
我有一个 asp.net 应用程序,允许用户为 SSRS 报告创建订阅。
我所有的报告都有@StartDate 和@EndDate 参数,它们的默认值为
=Today.AddDays(-14)
和
=Today
分别。
我的 C# 代码在加载订阅表单时检查参数的默认值,以预填充 AspxDateEdit 控件。这在我的开发环境 (NZ) 上一切正常。
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 的格式动态(特定于文化)。
在实时系统上加载报告的订阅表单时,我收到错误消息“字符串未被识别为有效的日期时间。”转储 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() 的格式时具体从哪里获取日期时间格式?据我了解我迄今为止的研究,这应该以 dd/MM/yyyy 的系统分配格式生成 =Today() 我还尝试将参数的默认值格式化为
- “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 更新 4)和 SSDTBI 插件(MSSQL Server Reporting Services 设计器版本 11.0.3436.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;
}
}