Skip to content

Try InvariantCulture #172 - #174

Open
jspraul wants to merge 1 commit into
OpenDBDiff:developfrom
jspraul:2024Nov-partition-date
Open

jspraul wants to merge 1 commit into
OpenDBDiff:developfrom
jspraul:2024Nov-partition-date

Conversation

@jspraul

@jspraul jspraul commented Nov 11, 2024

Copy link
Copy Markdown
Contributor

Unable to reproduce "String not recognized as a valid DateTime" but I'll give CultureInfo.InvariantCulture a shot in the three calls to DateTime.Parse in the entire app.

@alessandrovolpin

alessandrovolpin commented Mar 25, 2025 •

Copy link
Copy Markdown

I get the error with the following PARTITION FUNCTION ( Sql Server 2019 - Italian localization ):

CREATE PARTITION FUNCTION PF_TABLE
AS RANGE RIGHT FOR VALUES
(N'2015-01-01T00:00:00.000',
N'2016-01-01T00:00:00.000',
N'2017-01-01T00:00:00.000',
N'2018-01-01T00:00:00.000',
N'2019-01-01T00:00:00.000',
N'2020-01-01T00:00:00.000',
N'2021-01-01T00:00:00.000',
N'2022-01-01T00:00:00.000',
N'2023-01-01T00:00:00.000',
N'2024-01-01T00:00:00.000',
N'2025-01-01T00:00:00.000',
N'2026-01-01T00:00:00.000')

I suspect the problem is the "T".
I ended up modifyng the code of OpenDBDiff.SqlServer.Schema/Model/PartitionFunction.cs with TryParse.
Also seems that it's impossible to completely disable the partition-schema and partition-function analisys to avoid the error.
Thanks for pointing me in the right direction.


                Values.ForEach(item => { sqlvalues += "N'" + item + "',"; });
            else
                if (valueType == IS_DATE)
                {
                    Values.ForEach(item =>
                    {
                        if (DateTime.TryParse(item, CultureInfo.InvariantCulture, DateTimeStyles.None, out var dt))
                        {
                            sqlvalues += "'" + dt.ToString("yyyyMMddTHH:mm:ss.fff") + "',";
                        }
                        else
                        {
                            sqlvalues += "N'" + item + "',";
                        }
                    });
                }
            else
                    if (valueType == IS_UNIQUE)
                Values.ForEach(item => { sqlvalues += "'{" + item + "}',"; });
@@ -133,7 +147,16 @@ public string ToSqlAlter()
                    sqlmergue += "N'" + item + "'";
                else
                    if (valueType == IS_DATE)
                    {
                        if (DateTime.TryParse(item, CultureInfo.InvariantCulture, DateTimeStyles.None, out var dt))
                        {
                            sqlmergue += "'" + dt.ToString("yyyyMMddTHH:mm:ss.fff") + "'";
                        }
                        else
                        {
                            sqlmergue += "N'" + item + "'";
                        }
                    }
                else
                        if (valueType == IS_UNIQUE)
                    sqlmergue += "'{" + item + "}'";
@@ -152,7 +175,20 @@ public string ToSqlAlter()
                    sqsplit += "N'" + item + "'";
                else
                    if (valueType == IS_DATE)
                    {
                        if (DateTime.TryParse(item, CultureInfo.InvariantCulture, DateTimeStyles.None, out var dt))
                        {
                            sqsplit += "'" + dt.ToString("yyyyMMddTHH:mm:ss.fff") + "'";
                        }
                        else
                        {
                            sqsplit += "N'" + item + "'";
                        }
                    }
                else
                        if (valueType == IS_UNIQUE)
                    sqsplit += "'{" + item + "}'";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants