[Mono-bugs] [Bug 500987] SqlCommand with DateTime parameter throws exception "Error converting data type varchar to datetime" (impacts NHibernate and Castle ActiveRecord)

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri May 15 05:56:19 EDT 2009


User loic.nageleisen at gmail.com added comment

--- Comment #10 from Loic Nageleisen <loic.nageleisen at gmail.com>  2009-05-15 03:56:17 MDT ---
I think I found the cause by tooking a peek to Mono 2.4 source code via anonsvn

In Tds70.cs, you can find:

private string FormatParameter (TdsMetaParameter parameter)
            case "smalldatetime":
            case "datetime":
                DateTime d = Convert.ToDateTime (parameter.Value);
                value = String.Format (base.Locale,
                    "'{0:MMM dd yyyy hh:mm:ss.fff tt}'", d);

I then made a loop which rendered dates in en-US and fr-FR, and ran it locally.

Short month names in english:
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

Short month names in french:
janv. févr. mars avr. mai juin juil. août sept. oct. nov. déc.

Failing months have a dot in their name, successful months don't.

My first bet is MSSQL uses the OS to format and parse dates. As I am on a
French Windows which has zero support for localization, its API always returns
french names, thus there is zero chance MSSQL would parse US month names
correctly, because names all differ in some way or another.

My second bet is one of two:
- even french month names don't all match between Mono and Windows French,
either because there's no short version at all, or they're shortened
- the dot itself causes a parse error inside MSSQL.

This is coherent as for why it works for you and not for me, regardless of the
fact we use the exact same version (both number and locale) of MSSQL and Mono,
the sole difference being the OS.

In any case, I understand how the textual month representation has been used in
Mono to make date/month order unambiguous, but this has a number of
implications like this one... A first step may be to use the full month name
instead of the shortened version, but this is only a shaky fix, as it requires
the client to have is thread run in then same locale as the OS the MSSQL server
runs on.

Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

More information about the mono-bugs mailing list