I recently copied a web application to a new install of Windows 7 and SQL Server 2008 R2. The application uses LINQ to SQL. Somewhere along the line the parsing of POSTed date strings got screwed up. When the user enters a date string like 4/23/2011
, the application rejects it, throwing the error The value '04/23/2011' is not valid for Due.
Due (actually DueDate) is a开发者_StackOverflow社区 DateTime field in SQL Server.
This used to work fine. I assumed it was an issue with the machine's OS internationalization settings, so I checked and the short and long date formats are set to MM/dd/yyyy
and dddd, MMMM dd,yyyy
respectively, which looks OK to me. The SQL Server database language is set to English.
The partial class for this property looks like this:
[DisplayName("Due")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime? DueDate { get; set; }
There must be another date format setting I need to tweak. Where should I be looking?
Note: this may be more correctly a serverfault question, but I think devs are much more likely to run into this issue than sysadmins.
More info: SP_CONFIGURE 'default language'
returns:
default language 0 9999 0 0
Also: the default language for the database login I am using is English.
I assumed it was an issue with the machine's OS internationalization settings
No, it uses th USERS internationalization settings as told the server by the browser.
the application rejects it, throwing the error The value '04/23/2011' is not valid for Due.
And that is purely bad programming. You should always (!) enter dates either through a parameter or in the ISO form which is totally independant, if you really insist on creating your SQL strings yourself. That woudl be 2011-04-23. SQL Server will accept that format regardless of the locales set somewhere on client or server.
精彩评论