windows 日期中的月份无效 - Informix 中的日期格式偶尔会恢复

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1208377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:54:15  来源:igfitidea点击:

Invalid Month in Date - Date format in Informix reverts sporadically

c#asp.netwindowsinformixaix

提问by DarkUnderlord

So we have an AIX (ugh) server that runs an ERP system. This system's built in reports suck so I am of course tasked with building the reports we need.

所以我们有一个运行 ERP 系统的 AIX(呃)服务器。这个系统的内置报告很糟糕,所以我当然负责构建我们需要的报告。

I've got many reports I run and most of course are for specific dates, etc. The coding is done in C# running in ASP.net on a Windows 2003 Standard Server box. It uses the Informix CSDK to connect via the .Net Data Adapter that comes with the CSDK. The server runs Informix 10 on the AIX 5.2 server.

我有很多我运行的报告,当然大多数是针对特定日期等的。编码是在 C# 中完成的,在 Windows 2003 标准服务器框上的 ASP.net 中运行。它使用 Informix CSDK 通过 CSDK 附带的 .Net 数据适配器进行连接。服务器在 AIX 5.2 服务器上运行 Informix 10。

What's weird is that anytime we start and stop Informix or reboot the server, etc, it seems that Informix decides to change the way it's handled the date via the CSDK. If it's currently expecting MM/DD/YYYY then it'll eventually decide after the above situation that is wants it in YYYY/MM/DD. This usually ends up giving me an "Invalid Month in Date" error. Then I go into my dateformat function (made to easily allow me to fall back and forth) and manually change it over. A couple reports I built in the handling of this error and then retry the same query with the other format of the date. This of course is less than ideal and I'd like to get to the bottom of it!

奇怪的是,每当我们启动和停止 Informix 或重新启动服务器等时,Informix 似乎决定改变它通过 CSDK 处理日期的方式。如果它当前正在等待 MM/DD/YYYY,那么它最终会在上述情况之后决定在 YYYY/MM/DD 中​​需要它。这通常最终会给我一个“日期中的无效月份”错误。然后我进入我的 dateformat 函数(使我可以轻松地来回切换)并手动更改它。我在处理此错误时构建了一些报告,然后使用其他日期格式重试相同的查询。这当然不太理想,我想深入了解它!

Here is some pasted text from the ASP.net page error. Thanks!

这是 ASP.net 页面错误中的一些粘贴文本。谢谢!

Server Error in '/' Application.
ERROR [HY000] [Informix .NET provider][Informix]Invalid month in date
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about theerror and where it originated in the code.

Exception Details: IBM.Data.Informix.IfxException: ERROR [HY000] [Informix .NET provider][Informix]Invalid month in date

Source Error:

Line 479:
Line 480:        //aUsage = new IfxDataAdapter(sSelect_Usage, conn);
Line 481:        aUsage.Fill(dsUsage, "Usage");
Line 482:        aUsage.Dispose();
Line 483:        dtUsage = dsUsage.Tables["Usage"];


Source File: D:\Inetpub\reports2.oscarwinski.com\App_Code\IMRShipClass.cs    Line: 481

Stack Trace:

[IfxException: ERROR [HY000] [Informix .NET provider][Informix]Invalid month in date]
   IBM.Data.Informix.IfxConnection.HandleError(IntPtr hHandle, SQL_HANDLE hType, RETCODE retcode) +26
   IBM.Data.Informix.IfxCommand.ExecuteReaderObject(CommandBehavior behavior, String method) +654
   IBM.Data.Informix.IfxCommand.ExecuteReader(CommandBehavior behavior) +117
   IBM.Data.Informix.IfxCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +4
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +130
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +287
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
   IMRShipClass.Generate() in D:\Inetpub\reports2.oscarwinski.com\App_Code\IMRShipClass.cs:481
   IMRShip.testIMR() in D:\Inetpub\reports2.oscarwinski.com\IMRShip.aspx.cs:114
   IMRShip.btnExport2Excel_Click1(Object sender, EventArgs e) in D:\Inetpub\reports2.oscarwinski.com\IMRShip.aspx.cs:259
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082 

回答by RET

The date format is controlled by the client, not the server. Obviously it has a default (US format), but each client can dictate the format it wishes to use. This is done by setting the DBDATEenvironment variable. (There is also GL_DATEif you're using locales.)

日期格式由客户端控制,而不是服务器。显然它有一个默认的(美国格式),但每个客户端都可以指定它希望使用的格式。这是通过设置DBDATE环境变量来完成的。(GL_DATE如果您使用语言环境,也有。)

If the date format has switched, you should check the value of this environment variable. Is it being set by your middleware in some circumstances?

如果日期格式已切换,则应检查此环境变量的值。在某些情况下它是否由您的中间件设置?

回答by Jonathan Leffler

Urgh! .NET is not my strong point - you may have to adapt what I say to work correctly.

呃!.NET 不是我的强项 - 您可能必须调整我所说的才能正常工作。

On Windows, for better or worse, there is an Informix utility called SETNET32 which can be used to set Informix-related environment variables for Windows programs that connect to Informix databases. You don't mention whether you've set anything using this. Investigate whether it used by the Informix .NET provider.

在 Windows 上,无论好坏,都有一个名为 SETNET32 的 Informix 实用程序,可用于为连接到 Informix 数据库的 Windows 程序设置与 Informix 相关的环境变量。你没有提到你是否使用它设置了任何东西。调查它是否被 Informix .NET 提供程序使用。

You also do not mention whether the IDS server instance on the AIX box is restarted when the problem appears. I assume not. (The analysis might be different if it did.)

你也没有提到问题出现时是否重启了AIX盒子上的IDS服务器实例。我认为不是。(如果确实如此,分析可能会有所不同。)

The main environment variable that controls the date format is DBDATE. It takes various notations, such as:

控制日期格式的主要环境变量是 DBDATE。它需要各种符号,例如:

DBDATE=dmy4/        # 30/07/2009
DBDATE=mdy4/        # 07/30/2009
DBDATE=y4md-        # 2009-07-30
DBDATE=mdy20        # 073009

Don't use the last one. If there are changes in the value of DBDATE, this could account some of your problems, and setting DBDATEwould probably fix your problems.

不要用最后一个。如果DBDATE的值发生变化,这可能会说明您的一些问题,而设置DBDATE可能会解决您的问题。

There are other variables that affect date interpretation if DBDATEis not set; these include CLIENT_LOCALEand DB_LOCALE, and even GL_DATE. However, DBDATEhas the highest priority and is the one most people set most usually.

如果DBDATE未设置,还有其他变量会影响日期解释;这些包括CLIENT_LOCALEDB_LOCALE,甚至GL_DATE。但是,DBDATE具有最高优先级并且是大多数人最常设置的优先级。

回答by Frank Rotolo

Set DBDATE=MDY4/in the client app that runs the reports and every other client as well.

设置DBDATE=MDY4/在运行报告和所有其他的客户端以及客户端应用程序。

回答by bulltorious

This is probably unrelated, but I was receiving the same error. I ended up changing the single quotes in my SQL to parentheses. I was using parameterized SQL.

这可能是无关的,但我收到了同样的错误。我最终将 SQL 中的单引号更改为括号。我使用的是参数化 SQL。

SELECT id, descriptor FROM Foo WHERE descriptor >= '?'becomes

SELECT id, descriptor FROM Foo WHERE descriptor >= '?'变成

SELECT id, descriptor FROM Foo WHERE descriptor >= (?) 

回答by Venkat

DB2/Informix overrides the client date format. You contact your Db2 admin and set the date format in the server side once for all. We faced exactly same problem in AS400 (DB2) and DB admin never accepted it as in your case. Once the ISO date format syntax was taken from IBM site and given to DB2 admin he changed it. After that our programs worked fine with dates.
Good luck.

DB2/Informix 覆盖客户端日期格式。您联系您的 Db2 管理员并在服务器端设置日期格式。我们在 AS400 (DB2) 中遇到了完全相同的问题,而 DB 管理员从未像您的情况那样接受它。从 IBM 站点获取 ISO 日期格式语法并提供给 DB2 管理员后,他对其进行了更改。在那之后,我们的程序可以很好地处理日期。
祝你好运。

回答by bigcode

This may not be the case for your particular setup, but I have seen servers change the date format reported to databases when administrators have had their locale set to something differnt to the default, but only while they are logged in! You may wish to check the country/locale settings for EVERY user on the system.

对于您的特定设置,情况可能并非如此,但我已经看到服务器更改报告给数据库的日期格式,当管理员将他们的区域设置设置为与默认设置不同的内容时,但仅在他们登录时!您可能希望检查系统上每个用户的国家/地区设置。

回答by Nucleus

Start the informix instance as root instead of informix user .... it solves my pb and my night lol

以 root 而不是 informix 用户身份启动 informix 实例......它解决了我的 pb 和我的夜晚 哈哈