Skip to content

Dates and numbers when using locales other than en-US on the example of Test.SqlServer #17

Open
@Andrei-Errapart

Description

@Andrei-Errapart

Hi Joel,

I cannot change the regional settings the SQL Server and the computers have to use here. The SQL Server variable @@language returns 'Deutsch' and the regional settings are also German ("de-DE").

The following problems were encountered when running Test.SqlServer:

  1. Wrong format for the datetime strings. This happened during insert. The cure was to add "Current Language=us_english; " to the connection string.
  2. Now the format of the number 123.456 was "123,456" in the German locale and it was of course wrong for the SQL Server. This was fixed by adding the following to the beginning of Main:
    System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

I can think of the following options:

  1. Use the abovementioned fixes. I am not sure about alphabetical ordering; the initial tests show that it might work.
  2. Check all the uses of ToString() and put System.Globalization.CultureInfo.InvariantCulture everywhere.
  3. Create a function to format datetimes and strings according to the column type (as fetched from the database) and the CultureInfo.InvariantCulture.
  4. Skip conversion to string by stashing everything to query parameters. This makes debugging queries harder than it needs to be. On the plus side, all conversion woes should disappear and the library will tolerate any locale settings on both user side and SQL Server side.

There is a related problem, namely, I cannot insert into tables with columns of type "datetime", because there are too many decimal points and the SQL Server cannot convert it. Although the decimal points are zeroes, but still. Maybe just drop the extra zeroes?

Which options of the above are "no-no"? Is there any "right" solution? I would give implementing it a try.

I would be happy for all the input.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions