dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.26k stars 4.73k forks source link

[OLEDB] Text file created in US locale not readable on others as delimited file #29969

Closed maryamariyan closed 4 years ago

maryamariyan commented 5 years ago

Found this issue while running OLEDB outerloop tests on the CI machines with Spanish locale. (Initially reported in PR https://github.com/dotnet/corefx/pull/38024)

The failure seems to be in Spanish SKU of Windows: where a text file created in US locale cannot be read on other computers as a delimited file. (For more info check here)

cc: @tarekgh @saurabh500

maryamariyan commented 5 years ago
+ using System.Globalization;

        [OuterLoop]
        [ConditionalFact(Helpers.IsDriverAvailable)]
        public void DeriveParameters_NullConnection_Throws()
        {
+            Assert.True(CultureInfo.CurrentCulture.Name.Equals("en-US", StringComparison.OrdinalIgnoreCase));
+            CultureInfo.CurrentCulture = new CultureInfo("es-ES");
+            Assert.True(CultureInfo.CurrentCulture.Name.Equals("es-ES", StringComparison.OrdinalIgnoreCase));
            RunTest((command, tableName) => {
                using (var cmd = (OleDbCommand)OleDbFactory.Instance.CreateCommand())
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = @"SELECT * FROM " + tableName;  
                    cmd.Connection = null;

                    AssertExtensions.Throws<InvalidOperationException>(
                        () => OleDbCommandBuilder.DeriveParameters(cmd), 
                        $"{nameof(OleDbCommandBuilder.DeriveParameters)}: {nameof(cmd.Connection)} property has not been initialized.");
                }
            });
        }

I tweaked one of the failing tests locally to just run the test with spanish locale, and I still get the test pass successfully for myself locally meanwhile the same tests was failing on the CI with following message: (Refer to here)

Unhandled Exception of Type System.Data.OleDb.OleDbException
Message :
System.Data.OleDb.OleDbException : Text file specification field separator matches decimal separator or text delimiter.
Stack Trace :
   at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) in /_/src/System.Data.OleDb/src/OleDbCommand.cs:line 893
   at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) in /_/src/System.Data.OleDb/src/OleDbCommand.cs:line 857
   at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) in /_/src/System.Data.OleDb/src/OleDbCommand.cs:line 812
   at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) in /_/src/System.Data.OleDb/src/OleDbCommand.cs:line 771
   at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) in /_/src/System.Data.OleDb/src/OleDbCommand.cs:line 622
   at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() in /_/src/System.Data.OleDb/src/OleDbCommand.cs:line 916
   at System.Data.OleDb.Tests.OleDbCommandBuilderTests.RunTest(Action`2 testAction, String memberName) in /_/src/System.Data.OleDb/tests/OleDbCommandBuilderTests.cs:line 161
   at System.Data.OleDb.Tests.OleDbCommandBuilderTests.DeriveParameters_NullConnection_Throws() in /_/src/System.Data.OleDb/tests/OleDbCommandBuilderTests.cs:line 53

Making this change didn't give me a local repro.

tarekgh commented 5 years ago

@maryamariyan could you try move the lines

            Assert.True(CultureInfo.CurrentCulture.Name.Equals("en-US", StringComparison.OrdinalIgnoreCase));
            CultureInfo.CurrentCulture = new CultureInfo("es-ES");
            Assert.True(CultureInfo.CurrentCulture.Name.Equals("es-ES", StringComparison.OrdinalIgnoreCase));

inside the RunTest passed delegate?

maryamariyan commented 5 years ago

I moved the assertions also inside RunTest and around the ExecuteNonQuery call shown in the above call stack. It didn't seem to produce a repro.

cc: @saurabh500

saurabh500 commented 5 years ago

@maryamariyan The changes you made above for a repro, only changes the locale for C# test DeriveParameters_NullConnection_Throws right ? The error I believe should recur in case the Locale of the OS is changed to spanish. This error is coming from the OleDb layer which is simply being surfaced from OleDb provider. Hence the OleDb driver would have to operate in the spanish locale.

saurabh500 commented 5 years ago

Did you change the locale of the OS as well ?

maryamariyan commented 5 years ago

I changed the region locale to (Spanish - Spain). I'll see if there's more settings I need to change to get this repro.


UPDATE: Got repro by making change below:

It wasn't the system locale, since changing the locale below doesn't cause that repro:

ajcvickers commented 4 years ago

Closing as this is not something we plan to fix.